How can I get some part of the HTML body with JavaScript;
Eq:
<body>
Hello My Name is: Jane
</body>
How can I get and assign a variable, only the "Jane" part using JavaScript?
How can I get some part of the HTML body with JavaScript;
Eq:
<body>
Hello My Name is: Jane
</body>
How can I get and assign a variable, only the "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.