

Here, I will give you two example that will do it same thing with hide and show div or element by class or id on click event. We can do it jquery toggle element on click example. The jQuery toggle() method show or hide the elements in such a way that if the element is initially displayed, it will be hidden if hidden, it will be. You could style these yourself however you like, and everything would still work just fine. We will talk about toggle show hide div on click event. The rest of the CSS simply adds a border to our div (the border is hidden by the display rule, but becomes visible later) and fancied up our show/hide anchors by putting down/up arrows next to them and replacing the standard underline with a dotted border. The only truly important style is the “display: none ” rule on our. I’m technically doing far more styling than is necessary here, mostly for aesthetic purposes. Now that we have our XHTML in place, let’s put together our default CSS. Our JavaScript will use that single variable to do the rest of the work.

It’s also important to note that we’re calling our JavaScript using the “onclick” call, and passing it the name of our hidden div. The class names have no relationship to the JavaScript whatsoever, and could really be whatever you wanted them to be. This is a trick I’m using to simplify our JavaScript, as you’ll see later on down the road, so I suggest doing something similar.
JQUERY ONLCIK SHOWHIDE CODE
You’ll notice in the code above that all of our IDs are fairly similar. css ( 'display', 'block' ), except that the display property is restored to whatever it was initially. ( '.target' ).show () The matched elements will be revealed immediately, with no animation. Technically you could just use the IDs the set that CSS as well, but if you wanted more than one hidden section on your page, that could get messy. show () method is the simplest way to display an element: 1. By clicking the mouse, the (DIV) element is visible and by clicking again on the (DIV) element it hides.
JQUERY ONLCIK SHOWHIDE HOW TO
I n this tutorial, we are going to see how to show/hide a (DIV) element on mouse click with a slide effect in jQuery. I’m then using the classes to set our “default” CSS. How to show/hide a div with a slide effect in jQuery. The IDs are used by our JavaScript to locate and style the items appropriately. There are three things of importance here: the “show” anchor, the “hide” anchor, and our “hidden” div. We’ll start with structuring our XHTML appropriately.
