javascript - JQuery Extract value from a tag in a String - Stack Overflow

i want to extract value from the string here is my CodeJsvar a = "<strong>1954<strong>

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

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

Share Improve this question edited Aug 27, 2013 at 8:43 Hushme asked Aug 27, 2013 at 8:38 HushmeHushme 3,1441 gold badge22 silver badges27 bronze badges 2
  • jQuery or just Javascript? – Nikolaj Zander Commented Aug 27, 2013 at 8:47
  • @Nikolaj Zander- please see the tags – Hushme Commented Aug 27, 2013 at 8:49
Add a ment  | 

3 Answers 3

Reset to default 8

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

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

updated

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

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

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744389060a4571814.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信