I have a simple script to hide/show a table row. I'd like it to look for an additional class, but I can seem to get it to work. Here is the original:
jQuery(function () {
jQuery(".toggle").click(function () {
jQuery(this).closest("tr").next("tr").find(".hide1").slideToggle("none");
});
});
I tried adding an 'or' operator to specify another class, but that doesn't work:
jQuery(function () {
jQuery(".toggle").click(function () {
jQuery(this).closest("tr").next("tr").find(".hide1" || ".hide2").slideToggle("none");
});
});
Can someone point out my error - Javascript is not my strong suit.
I have a simple script to hide/show a table row. I'd like it to look for an additional class, but I can seem to get it to work. Here is the original:
jQuery(function () {
jQuery(".toggle").click(function () {
jQuery(this).closest("tr").next("tr").find(".hide1").slideToggle("none");
});
});
I tried adding an 'or' operator to specify another class, but that doesn't work:
jQuery(function () {
jQuery(".toggle").click(function () {
jQuery(this).closest("tr").next("tr").find(".hide1" || ".hide2").slideToggle("none");
});
});
Can someone point out my error - Javascript is not my strong suit.
Share Improve this question asked Jan 20, 2012 at 19:35 PeachyPeachy 6534 gold badges21 silver badges31 bronze badges 3- Please post the HTML you're working with. – David Thomas Commented Jan 20, 2012 at 19:37
- 1 I don't really think it is necessarily in this case. The JS seemed to be clear enough given the quantity of correct answers. Thanks everyone! – Peachy Commented Jan 20, 2012 at 19:48
- Possibly not necessary, but it might have improved the answers at least a little to see what you're working with. But if the posted answers work, and solve your problem, then perhaps not in this case. – David Thomas Commented Jan 20, 2012 at 19:50
5 Answers
Reset to default 9Use a ma. This is the multiple selector.
.find(".hide1,.hide2")
Doing...
.find(".hide1" || ".hide2")
...is valid code, but it will be interpreted as...
.find(".hide1")
try this:
find(".hide1,.hide2")
See: Multiple Selector
just give it ma separated
.find(".hide1,.hide2").
To find either class-name, just use a ma-separated list:
.find('.hide1, .hide2')
This assumes, of course, that the rest of your jQuery works.
This should do the trick!
jQuery(function () {
jQuery(".toggle").click(function () {
jQuery(this).closest("tr").next("tr").find('.hide1, .hide2').slideToggle("none");
});
});