How to get numbers from the Paragraph tag?

前端 未结 2 1881
一生所求
一生所求 2021-01-25 00:02

I am having some values in my paragraph tag. I am trying to get the values from the paragraph tag. But I am unable to get the values. For example,

HTML Code:

<         


        
相关标签:
2条回答
  • 2021-01-25 00:32

    As a string :

     var str = $('#value').text()
    

    As a number :

     var nb = parseInt($('#value').text().trim(), 10);
    
    0 讨论(0)
  • 2021-01-25 00:36

    you want to do

    var value = $('#value').html();
    

    That should give you the value you're looking for. The html() function returns all the html code within the selector. In your case it's just the text.

    If you want that as a number instead of a string just wrap it in parseInt()

    var integer_value = parseInt($('#value').html());
    
    0 讨论(0)
提交回复
热议问题