![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hello I'm trying to implement a minimal navigation bar using jQuery's toggleClass() function but can't seem to get it working, no matter how many tips from all you gurus out there that I follow meticulously. It's the .img_selector div at the bottom of the page: http://www.thomasrugani.com/static/designobjects/02.html I want to toggle the 'active' class for each <a> when it's selected, to indicate which image is showing, so after calling jQuery, in the head> I've got script type="text/javascript" $(document).ready(function(){ $('a').click(function () { $(this).toggleClass('active'); }); }); /script then the links, which also include the showPic function: --------------- div class="img_selector" Image ul li><a class="active" onclick="return showPic(this)" href="images/ stoppino_tictacs_lit.jpg" title="">01</a></li li><a onclick="return showPic(this)" href="images/ stoppino_tictacs.jpg" title="">02</a></li li><a onclick="return showPic(this)" href="images/ stoppino_tictac_base1.jpg" title="">03</a></li li><a onclick="return showPic(this)" href="images/ stoppino_tictac_base2.jpg" title="">04</a></li /ul /div -------------------- Can anyone see what I'm missing? Thanks in advance.. Bernard |
#3
| |||
| |||
|
|
Try this script $(document).ready(function(){ * $('a').click(function() { * * $(this).toggleClass('active'); * * showPic(this); * * return false; * });}); /script ... div class="img_selector">Image * * * *<ul * * * * * * * *<li><a class="active" href="images/stoppino_tictacs_lit.jpg" title="">01</a></li * * * * * * * *<li><a href="images/stoppino_tictacs.jpg" title="">02</a></li * * * * * * * *<li><a href="images/stoppino_tictac_base1.jpg" title="">03</a></li * * * * * * * *<li><a href="images/stoppino_tictac_base2.jpg" title="">04</a></li * * * *</ul /div - Richard On Mon, Nov 2, 2009 at 2:48 PM, Bernard Elsmere bernard.elsm... (AT) gmail (DOT) com>wrote: Hello I'm trying to implement a minimal navigation bar using jQuery's toggleClass() function but can't seem to get it working, no matter how many tips from all you gurus out there that I follow meticulously. It's the .img_selector div at the bottom of the page: http://www.thomasrugani.com/static/designobjects/02.html I want to toggle the 'active' class for each <a> when it's selected, to indicate which image is showing, so after calling jQuery, in the head> I've got * * * *<script type="text/javascript" * * * * *$(document).ready(function(){ * *$('a').click(function () { * * *$(this).toggleClass('active'); * *}); *}); * * * *</script then the links, which also include the showPic function: --------------- div class="img_selector" Image * * * *<ul * * * * * * * *<li><a class="active" onclick="return showPic(this)" *href="images/ stoppino_tictacs_lit.jpg" title="">01</a></li * * * * * * * *<li><a onclick="return showPic(this)" *href="images/ stoppino_tictacs.jpg" title="">02</a></li * * * * * * * *<li><a onclick="return showPic(this)" *href="images/ stoppino_tictac_base1.jpg" title="">03</a></li * * * * * * * *<li><a onclick="return showPic(this)" *href="images/ stoppino_tictac_base2.jpg" title="">04</a></li * * * *</ul /div -------------------- Can anyone see what I'm missing? Thanks in advance.. Bernard |
#4
| |||
| |||
|
#5
| |||
| |||
|
|
I'm a little confused, but before I examine more closely, one thing I'd like an answer to is whether you have defined the initial "active" a> incorrectly. You gave the link tohttp://www.thomasrugani.com/static/designobjects/02.html That's 02.html - NOT 01.html Yet, when I look at the source of 02.html, here is what I see: li><a href="01.html" class="active">Design Objects</a><br/></li Maybe your definition of "active" should refer to all the 02's? It would help to see your class styling for active. *Can you move it into the source, so that View Page Source will show what the styling criteria is? Also, post a description of what the "active" style is supposed to change? *What are you trying to do? It is confusing that every one of your pages: 01, 02, and 03 show 01 as active in the source. On a last-second re-look, it occurs to me that your <a> causes a re- direct to another page. *How do you stall (delay) (avoid immediate loss of control) in order to change the class in the current page script? *Once you redirect, I think you are gone. *Your current page loses control. I have had this happen in another context, so I bet this is it. Do not use <a>. *Use just the <li> and give it a style that makes it look like a link. *Use onclick() only in your Jquery. *In your Jquery, change the class, and then.... redirect. *I believe it is a javascript "window.location=..." that accomplishes the same thing is <a>'s re- direct. window.location = 'http://www.yourdomain.com'*// this immediately takes you to the page yourdomain. Now, once you are in the new page, the importance of knowing what element had the active class in the previous page is defeated. *In the new page, you will know nothing about what used to be in the old page. *So, what is the point of the needing to know active class if you are leaving the page? |
![]() |
| Thread Tools | |
| Display Modes | |
| |