I know this would involve Jquery, I am not as learned as I’d like to be in mocking this up myself. I know there is a toggle function, but dont know how I’d mock this up for my own use.
This might be possible in css3 too? But Im guessing Jquery would be a better cross browser solution.
Assuming you have a button, or other element, with a specific
id:Or, to be a little prettier:
This is, given some fairly specific mark-up constraints and low cross-browser compatibility requirements, possible in CSS, albeit only in CSS3:
HTML:
CSS:
JS Fiddle demo.
The above can be adapted to apply, of course, to specific classes rather than all
divelements, and this is one (though perhaps not the only) way to work with specific classes, using the general sibling combinator~:HTML:
CSS:
JS Fiddle demo.
Bear in mind, though, that CSS selection can only select elements that appear later in the DOM, so to show all the
divelements ofclass="one"thetargetfor the link has to be the first element of thatclass, so, to be concise, the target has to be, literally, the#firstOne. Hence the name, really, but it seemed worth specifying that.References:
fadeToggle().:targetpseudo-class, at the W3.slideToggle().toggle().