For example our url: example.com
and source code is:
<html>
<head>
<body>
Hello My Name is: Jane
</body>
</head>
</html>
My question is: How we can get only "Jane" part using javascript?
For example our url: example.com
and source code is:
<html>
<head>
<body>
Hello My Name is: Jane
</body>
</head>
</html>
My question is: How we can get only "Jane" part using javascript?
While looking at this page, pop up your browser's Javascript console and type:
$('body').text().match(/Hello My Name is: (\w+)/)
and you may see
["Hello My Name is: Jane", "Jane"]
You could assign the array to a variable and extract the second element.
One one line:
$('body').text().match(/Hello My Name is: (\w+)/)[1]
"Jane"
However, note that there can be horrific consequences of extracting things out of HTML with a regular expression and so it is considered a bad practice.