What would cause myDivId.toggle() to work while myDivClass.toggle() does not?
-
11-09-2019 - |
Question
I have some DIVs that I am using JQuery to hide and show using the toggle()
function. This has been working fine.
But I just recognized some relationships between some of these DIVs that would allow me to group some of them into a class.
I was hoping that this would allow me to toggle the DIV class instead of each of the DIV ids.
So I want to do this:
$("#myDIVId1").click(function ()
{
$("myDIVClass").hide();
$("#myToggle1").toggle();
});
Instead of this:
$("#myDIVId1").click(function ()
{
$("#myToggle2").hide();
$("#myToggle3").hide();
$("#myToggle4").hide();
$("#myToggle5").hide();
$("#myToggle1").toggle();
});
But only this verbose ID access seems to work. Any ideas why?
Solution
When you select the class, you need to put a '.'
$(".myDIVClass").hide();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow