user2310422
user2310422

Reputation: 555

How to get the content outside of an element

Below is my code, my goal is when the user clicks the button with a class named click_me, I want to alert the content inside the class named content. I've tried doing:

JS:

alert($(this).closest('.content').html()); 

But it didn't work.

HTML:

<tr>
    <div class="content">Hello</div>
    <div>
        <div>
            <ul>
                <li></li>
                <li></li>
                <li></li>
            </ul>
            <ul>
                <li><input type="button" class="click_me" value="Click Me"/></li>
                <li></li>
            </ul>
        </div>
    </div>
</tr>   

Upvotes: 0

Views: 82

Answers (3)

jasse
jasse

Reputation: 101

Try this :

   alert($(this).closest('tr').find('.content').html());

Upvotes: 0

Christian
Christian

Reputation: 7429

$(function(){
 $(".click_me").on("click",function(){
   alert($(".content").html());
 });
})

Upvotes: 0

palaѕн
palaѕн

Reputation: 73966

Try this:

alert($(this).closest('tr').find('.content').html());

Upvotes: 2

Related Questions