hi,
I have to do in plain JavaScript something that I’m much more used to doing in jQuery… this is for a standard tabbed-content show/hide div switcheroo… here’s the jQuery code:
$('.tabs a').click(function(e) {
e.preventDefault();
$('.tab_content_wrapper').hide();
$('.tab_content_wrapper').eq( $(this).index('.tabs a') ).show();
$('.tabs a').removeClass('tab_on').addClass('tab_off');
$(this).addClass('tab_on').removeClass('tab_off');
});
the main difficulty in doing this in plain JS is in grabbing which anchor was clicked…
this did not do the trick…
[INDENT]if ( document.addEventListener ) {
tabs.childNodes[i].addEventListener(“click”, function(){ this.style.border = ‘1px solid red’; }, false);
} else if ( document.attachEvent ) {
tabs.childNodes[i].attachEvent (“click”, function(){ this.style.border = ‘1px solid red’; });
}[/INDENT]
‘this’ evidently does not refer to the element that was clicked on…
also, can you refer to elements by their class name?
also, is it possible to do event-binding in plain JavaScript w/o using individual id’s for the clicked-on elements? like I did, (thanks to help from people at the jQuery forums) in the code I posted above? if not I don’t mind using element id’s, but still, if possible would like something like if second tabbed was clicked show 2nd div…
would appreciate some help & suggestions as to how to convert this jQuery functionality to plain JS…
thank you…
(PS: can’t use
tags.. they mess things up.. hide part of the post.. (I guess new interface still a bit buggy...;-) )