Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery find and get html

Tags:

jquery

I'm trying to grab the entire html of .spec including the <ul class="spec"></ul> but using the below code it grabs only the children of .spec

HTML

<div class="single-vacancy">
    <p class="title"><strong>This title</strong></p>
    <span class="read-more">View Vacancy</span>
    <ul class="spec">
        <li>List</li>
        <li>List</li>
        <li>List</li>
    </ul>
</div>

jQuery

$('.read-more').click(function() {
    var role = $(this).next('.spec').html();
});
like image 798
ngplayground Avatar asked Feb 03 '26 07:02

ngplayground


1 Answers

Or the jquery way:

var role = $(this).next('.spec').prop('outerHTML');

Using html() returns only the content HTML (innerHTML) not the outer HTML.

like image 126
A. Wolff Avatar answered Feb 05 '26 09:02

A. Wolff



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!