How to get the text of paragraph tag html in Jquery
Dung Do Tien Apr 10 2020 487
I have some code below and I want to get the current text of <p> tag using Jquery.
<div class="col-md-2 content-article-detail">
<h1>Title of news</h1>
<div class="sapo">
some short content of article
</div>
<div class="detail">
<p> this is description detail of article </p>
</div>
</div>
How to achieve it? Thanks in advance.
Have 1 answer(s) found.
- S0
Sandeep Kumar Apr 11 2020
With Jquery you can use to Text() or Html() functions to get text or content of <P> tag. In your case you can get as below:
var textNews = $(".content-article-detail .detail > p").text()
OR write shorter
var textNews = $(".detail p").text()
Or more shorter
var textNews = $("p").text()
I recommend you use it in the first way when you have more HTML in the page.
* Type maximum 2000 characters.
* All comments have to wait approved before display.
* Please polite comment and respect questions and answers of others.