jQuery question #gazillion
- Started
- Last post
- 7 Responses
- funkage0
What if ...
You assigned those two with the same IDs:
<a href="#prod1" id="foobar">Slide 1</a>
<a href="#prod-2" id="foobar">Go to slide 2</a>Then in the js you could store the id of the clicked button and have:
var storedid = $(this).attr('id');
$('#wslide4-menu a[id='storedid']').addClass('wac...
- supersimple0
1 - IDs are to be used once only
i dont want to wade through the rest of your code, but you will want to target the elements by attribute.
http://api.jquery.com/attribute-…
eg. $("a[href='#prod-2']")
- redred0
There are a few different ways to do this. One way is to write one function that takes care of assigning the "active" state. The function should not be associated with either of the slide links so that slide link can trigger it. Then you assign an onclick handler to each of the slide links and call that function. Hope that makes sense.
- redred0
If I understand your question correctly...
<a href="#" id="foobar1">Slide 1</a>
<a href="#" id="foobar2">Slide 2</a>/* One function */
function activateSomeElement() {
$("#foobar1").addClass("active...
$("#foobar2").addClass("active...
}/* Two click handlers */
$("#foobar1").click(function() {
activateSomeElement();
});
$("#foobar2").click(function() {
activateSomeElement();
});
- Jaline0
Asked this at the jQuery forum before and someone posted an answer. I went off of his post and came up with this, and it worked:
$('#wslide4-menu.prod-menu a').click(function() {
$('#wslide3-menu.prod-menu a').addClass('wactive');
$('#wslide3-menu.prod-menu a:first').removeClass('wactive...
});Thanks for the other suggestions though!
- fugged0
Try this.
http://pastebin.com/d4L1jnAAUsing child selectors should work cross browser, but locks you into an structure in your HTML that can't be changed w/o updating the JavaScript as well.
- Thanks. It's just one part of the HTML anyway...not a big deal...Jaline