I have this line of Javascript which runs a function I sourced online. However it turns out to not be ie compatible so I’m looking to convert it to a Jquery call.
I have absolutely no Jquery experience and while the documentation is good, I need a hand understanding how to get it to gel with pre-existing Javascipt.
classElements[i] = document.getElementsByClassName(show_hide_class_selectors[i]);
I have found the class selector at http://api.jquery.com/class-selector/ which seems to do what I want.
If I used this line (show_hide_class_selectors[i] is a string)
classElements[i] = $("." + show_hide_class_selectors[i]);
Will classElements[i] then contain all nodes of the class provided by show_hide_class_selectors[i]?
I’m asking now so I don’t spend the next 2 hours downloading, messing and then getting pissed with it.
Yes,
$(".foo")will return all nodes having the classfoo, but wrapped in a jQuery object.If you just want a plain array of DOM elements, you’ll need to do
$(".foo").get().