homepage Welcome to WebmasterWorld Guest from 54.167.11.16
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
Jquery event issue
frankstuner




msg:4394011
 7:20 am on Dec 4, 2011 (gmt 0)

I'm new to jquery and javascript in general, I've been trying to modify one of the examples off the jquery site but have been having trouble adding classes/id's to example and having it work in the same way.

This is the jquery page [api.jquery.com...]

This is the original version:
<ul>
<li>item 1
<ul>
<li>sub item 1-a</li>
<li>sub item 1-b</li>
</ul>
</li>
<li>item 2
<ul>
<li>sub item 2-a</li>
<li>sub item 2-b</li>
</ul>
</li>
</ul>
<script>function handler(event) {
var $target = $(event.target);
if( $target.is("li") ) {
$target.children().toggle();
}
}
$("ul").click(handler).find("ul").hide();</script>


This is what i was trying to do:
<ul id="nav">
<li class="parent-sub">item 1
<ul class="child-nav">
<li class="child-sub">sub item 1-a</li>
<li class="child-sub">sub item 1-b</li>
</ul>
</li>
<li class="parent-sub">item 2
<ul class="child-nav">
<li class="child-sub">sub item 2-a</li>
<li class="child-sub">sub item 2-b</li>
</ul>
</li>
</ul>
<script>
function handler(event)
{
var $target = $(event.target);
if( $target.is("li.child-sub") )
{
$target.children().toggle();
}
}
$("ul#nav").click(handler).find("ul.child-nav").hide();
</script>


When I've tried a few different configs it still breaks the functionality in one way or another.

Can anyone point me in the right direction please?

 

frankstuner




msg:4394031
 10:18 am on Dec 4, 2011 (gmt 0)

all good, worked it.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved