How to get the text of paragraph tag html in Jquery
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.
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.