jQuery pull out text inside div but not in p tag

2019-07-03 15:19发布

In the below code I would like to put a variable to the text within the div but NOT whats inside the p tag:

 <div class="review-content merchant-review-content">
     I want to grab this text
     <p class="review-rating">
     From a cool person
     - My Date goes here
     -
     A Review
    </p>
    <div></div>
</div>

Additionally I would like to only pull the first 250 characters of it, if thats possible!

2条回答
Fickle 薄情
2楼-- · 2019-07-03 15:48

Try this snippet:

$("div.review-content").clone().children('p').remove().end().html().substring(0,250);
查看更多
登录 后发表回答