Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to append clicked li text in div box?

i have the following html :-

<span id="event">
<ul>
    <li>Activities
    <ul>
        <li>Physical1
        <ul>
            <li>Cricket
            <ul><li>One Day</li>
            </ul>
            </li>
        </ul>
        </li>
    </ul>
    </li>
</ul>
</span>
<div id="activity"></div>

i want to set the click event on every li using jquery click function
it works perfect but i want to set this li text in #activity div
here is what i have tried:

$("#event ul li").live("click", function(event){
    event.stopPropagation();
    alert($(this).text());
    $("#activity").append($(this).text());
    return false;
});

http://jsfiddle.net/Va5E4/7/

now problem in them when i am click on li its append all the li text in div, i want only clicked li text.
when click on li there text append in div tag eg:- click on Cricket then cricket append in div when click on One Day append on Div...

how do i do this? thanks.

like image 634
jack lanza Avatar asked Nov 20 '25 17:11

jack lanza


1 Answers

You can grab the first childNode of the clicked li and append that:

$("#activity").append(this.childNodes[0].nodeValue);

Here's a fiddle

like image 126
billyonecan Avatar answered Nov 23 '25 06:11

billyonecan



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!