I am trying to show/hide three div based on jquery using <a href="#id"> .but the code is not working.It works fine when i map using <a> link using rel attribute.
For ex :<a rel="cat1" class=""selected">
I tried a watered down version of what you have here, and the concept of setting the onclick of a selected collction of anchors and using the href to find a div by id works. I don't know, however, what ddtabcontent() is. It's likely that it is doing something
that is resulting in either the class being changed or it otherwise not being discoverable by jquery.
"Dream as if you'll live forever, live as if you'll die today." --James Dean
What exactly isn't working? Are all your content divs being hidden properly? Is the appropriate one not reappearing?
My guess is that something is altering the class of your content divs so that it cannot be found by jQuery. You might need to add some alerts in there to find out what is going on. Try something like this:
ram07
Member
1 Points
21 Posts
show/hide div using jquery and c#
Dec 21, 2012 03:53 PM|LINK
I am trying to show/hide three div based on jquery using <a href="#id"> .but the code is not working.It works fine when i map using <a> link using rel attribute.
For ex :<a rel="cat1" class=""selected">
Default.aspx
==============
<div id="featuredleftdiv"> <script type="text/javascript"> var featuredposts = new ddtabcontent("featuredposts") featuredposts.setpersist(true) featuredposts.setselectedClassTarget("link") featuredposts.init(10000) </script> <ul id="featuredposts" class="featuredposts"> <li><a href="#cat1" class="menu">a</a></li> <li><a href="#cat2" class="menu">b</a></li> <li><a href="#cat3" class="menu">c</a></li> </ul> <div class="clear"> </div> <div id="cat1" class="featuredposts_content"> <asp:UpdatePanel ID="UpdatePanel4" runat="server"> <ContentTemplate> <asp:ListView ID="ListView4" runat="server" GroupItemCount="1" OnPagePropertiesChanging="ListView4_PagePropertiesChanging"> </ContentTemplate> </asp:ListView> </asp:UpdatePanel> </div> <div id="cat2" class="featuredposts_content"> <asp:UpdatePanel ID="UpdatePanel5" runat="server"> <ContentTemplate> <asp:ListView ID="ListView5" runat="server" GroupItemCount="1" OnPagePropertiesChanging="ListView4_PagePropertiesChanging"> </ContentTemplate> </asp:ListView> </asp:UpdatePanel> </div> <div id="cat3" class="featuredposts_content"> <asp:UpdatePanel ID="UpdatePanel5" runat="server"> <ContentTemplate> <asp:ListView ID="ListView5" runat="server" GroupItemCount="1" OnPagePropertiesChanging="ListView4_PagePropertiesChanging"> </ContentTemplate> </asp:ListView> </asp:UpdatePanel> </div> JQuery ========= In Head section of html <script type="text/javascript" src="Scripts/jquery-1.8.3.js"> </script> <script type="text/javascript"> $("a.menu").click(function () { $("div.featuredposts_content").hide(); $($(this).attr('href')).show(); return false; }); </script>AceCorban
Star
12320 Points
2270 Posts
Re: show/hide div using jquery and c#
Dec 21, 2012 04:06 PM|LINK
I tried a watered down version of what you have here, and the concept of setting the onclick of a selected collction of anchors and using the href to find a div by id works. I don't know, however, what ddtabcontent() is. It's likely that it is doing something that is resulting in either the class being changed or it otherwise not being discoverable by jquery.
ram07
Member
1 Points
21 Posts
Re: show/hide div using jquery and c#
Dec 22, 2012 12:48 AM|LINK
ddlTabContent() is a javascirpt timer which changes every div for 10 secs.
AceCorban
Star
12320 Points
2270 Posts
Re: show/hide div using jquery and c#
Dec 22, 2012 08:04 PM|LINK
What exactly isn't working? Are all your content divs being hidden properly? Is the appropriate one not reappearing?
My guess is that something is altering the class of your content divs so that it cannot be found by jQuery. You might need to add some alerts in there to find out what is going on. Try something like this:
$("a.menu").each(function () { alert($(this).attr('href').length); });if you get a bunch of zeros, that means jquery can't find those items.