Hushme
Hushme

Reputation: 3144

JQuery Extract value from a tag in a String

i want to extract value from the string

here is my Code

Js

var a = "<strong>1954</strong>im the text";
var pageNum = a.split("<strong>").slice(1)
alert(pageNum);

i simply want to extract value in strong tag i have tried but so far no luck

Upvotes: 2

Views: 1183

Answers (3)

Nikolaj Zander
Nikolaj Zander

Reputation: 1270

Here is how you get your Value from the string without jQuery:

var pageNum = a.substring(a.indexOf('<strong>' + 8, ), a.indexOf('</strong>'))

Upvotes: 2

Rituraj ratan
Rituraj ratan

Reputation: 10388

   var text= $("div strong").text();

updated

 var text= $(a).filter('strong').text();

Upvotes: 2

Arun P Johny
Arun P Johny

Reputation: 388446

You can find the strong element inside the div and then get its contents using .text()

var pageNum = $("div").find('strong').text()

With the update

jQuery(function(){
    var a = '<strong>1954</strong>im the text';
    var pageNum = $(a).filter('strong').text();
    alert(pageNum);
})

Demo: Fiddle

Demo: Fiddle

Upvotes: 8

Related Questions