Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8748951
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:36:45+00:00 2026-06-13T12:36:45+00:00

there is some html code like this: <ul> <li id=’root’ class=’tree-node’> root <ul> <li

  • 0

there is some html code like this:

<ul>
    <li id='root' class='tree-node'>
      root
      <ul>
        <li class='tree-node' id='node1'>node1</li>
        <li class='tree-node' id='node2'>node2</li>
        <li class='tree-node' id='node3'>node3</li>
        <li class='tree-node' id='node4'>node4
            <ul>
                <li class='tree-node' id='node4-1' >node4-1</li>
                <li class='tree-node' id='node4-2' >node4-2</li>                    
            </ul>
        </li>
      </ul>
    </li>

<ul>

i want to bind click event to each tag which has tree-node class

and also binding click event to document

here is my code:

$(".tree-node").click(function(e){
    console.log($(this).attr("id"));
});

$(document).click(function(e){
    console.log("document clicked!");   
});

Is there any alternative for stopPropagation() to stop event bubbling from node4-2 to its parents?

fiddle : http://jsfiddle.net/R6ySc/

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T12:36:46+00:00Added an answer on June 13, 2026 at 12:36 pm

    You could just use the document click event and handle everything from there.

    $(document).click(function(e){
        console.log("document clicked!");    
        var t = $(e.target);
        if(t.attr("class") == "tree-node") {
            console.log("tree node clicked");
        }
    });​
    

    Check this fiddle: http://jsfiddle.net/R6ySc/3/

    as an alternative, you can also specify a selector in the onclick event for the document (check the jQuery documentation for this):

    $(document).on("click", ".tree-node", function(e) {
        e.stopPropagation();
        console.log("tree node '" + $(this).attr("id") + "' clicked");
    });​
    

    for reference, check the comments below

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem where I have some html like this <p>There is the
I have some HTML like this: <a class=button> <span> <span> <span class=buttonspan>Content</span> </span> </span>
For some landing page templates there is code like this: <?php $Name = 'FOO';
I have html code that looks roughly like this: <div id=id1> <div id=id2> <p>some
I have a web application with bunch of HTML code. There are some style-attributes
Is there some magic existing code in MVC 2 to Html.Encode() strings and allow
I have a servlet coded in Scala. I have some code like this in
I'm rendering some HTML in a QT QLabel. The HTML looks like this: <pre>foo\tbar</pre>
I'm using jquery to build some html and the final code should look like
I have some code like below $(html).on(change, input['data-href'], function() { var href, obj, params;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.