I have some html in string form.
var html = "
<html>
<head>
<title>
Some Text
</title>
</head>
<body>
<h1>
My First Heading
</h1>
<p>
My first paragraph.
</p>
</body>
</html>
";
It has title tag inside it. How can I get the text inside title tag using jquery or javascript?
You can get it by using . text() , $('button'). text();
jQuery [attribute|=value] Selector The [attribute|=value] selector selects each element with a specified attribute, with a value equal to a specified string (like "en") or starting with that string followed by a hyphen (like "en-us"). Tip: This selector is often used to handle language attributes.
Again, on Windows, you can select Ctrl + F and then type “title” to quickly find the Title. That's all there is to it.
In JavaScript, simply
document.title
For sample code
<html>
<head>
<title>My Page Title</title>
</head>
<body>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = document.title;
</script>
</body>
</html>
Just try with:
var title = $(html).filter('title').text();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With