jQuery Toggle() Method

jquery toggle

jQuery Toggle() Method

How to do jquery Toggle() method to show/hide onclick

The jQuery toggle() method is used to toggle between the hide() and show() method. It shows the hidden elements and hides the shown element.

HTML :

<button type="button" id="toggle">Toggle</button>
	<div id="text">
		Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
	</div>

Specify a button with an id along with a div containg the text. Also specify an id for the div.

Include the jquery.min.js file

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

Click here to get the jquery.min.js file contents

jQuery

<script type="text/javascript">
	$(document).ready(function()
	{
		$( "#toggle" ).click(function() {     
		   $('#text').toggle();
		});
	});
</script>

In script take the click event, onclick the button specify toggle() function. The jQuery toggle() function is an inbuilt function so all we have to do is just specify the function.

For printing Date with javascript/jquery click here.

69 thoughts on “jQuery Toggle() Method

  1. I?m impressed, I have to admit. Rarely do I encounter a
    blog that?s equally educative and amusing, and without a doubt, you have hit the nail on the head.
    The issue is something which not enough people are speaking intelligently about.
    Now i’m very happy that I stumbled across this during
    my hunt for something regarding this.

  2. Excellent blog! Do you have any recommendations for
    aspiring writers? I’m hoping to start my own site soon but I’m a little lost on everything.
    Would you advise starting with a free platform like WordPress or go for a paid option? There are so many options
    out there that I’m completely confused .. Any recommendations?
    Thanks a lot!

  3. Howdy just wanted to give you a quick heads up. The text in your post seem to be running off the screen in Ie.
    I’m not sure if this is a format issue or something to do
    with web browser compatibility but I thought I’d post to let you know.
    The design look great though! Hope you get the issue fixed soon. Cheers

    My web blog 홀덤하는방법

  4. Hey I know this is off topic but I was wondering if you knew of any widgets I could add to my blog
    that automatically tweet my newest twitter updates.
    I’ve been looking for a plug-in like this for quite some time and was hoping maybe you would have some experience with something like this.
    Please let me know if you run into anything. I truly enjoy reading your
    blog and I look forward to your new updates.

  5. Hi, I do think this is a great blog. I stumbledupon it
    😉 I’m going to revisit yet again since i have bookmarked it.

    Money and freedom is the best way to change,
    may you be rich and continue to guide others.

  6. If some one wishes to be updated with latest technologies afterward he must be pay a
    quick visit this web page and be up to date every day.

  7. Thanks for your marvelous posting! I really enjoyed
    reading it, you might be a great author. I will always bookmark
    your blog and definitely will come back from now on. I want to encourage that you continue your great
    work, have a nice afternoon!

  8. I have been exploring for a little for any high
    quality articles or blog posts on this kind of house . Exploring in Yahoo I finally
    stumbled upon this web site. Reading this info So i
    am satisfied to convey that I’ve an incredibly
    good uncanny feeling I came upon exactly what I needed.
    I most no doubt will make certain to do not put out of
    your mind this website and give it a look regularly.

  9. You’re so cool! I do not think I’ve truly read through something like this before.
    So great to find someone with unique thoughts on this issue.
    Seriously.. thank you for starting this up. This website is something that is required on the internet, someone with a bit of originality!

  10. Greetings. I know this is somewhat off-topic, but I was wondering if you knew where I could get a captcha plugin for my comment form?
    I’m using the same blog platform like yours, and I’m having difficulty finding one?
    Thanks a lot.

  11. You’ve made some good points there. I checked on the web for additional information about the issue and found most
    people will go along with your views on this web site.

  12. Its like you read my mind! You appear to know a lot approximately this, such as you wrote the guide in it or something.
    I believe that you can do with some percent to pressure the message home a little bit, however instead of that, that
    is excellent blog. A great read. I will certainly be back.

  13. We absolutely love your blog and find most of your post’s to be what precisely I’m
    looking for. Would you offer guest writers to write content to suit your needs?
    I wouldn’t mind composing a post or elaborating on a number of the subjects you write concerning here.
    Again, awesome blog!

  14. An outstanding share! I’ve just forwarded this onto a
    colleague who has been conducting a little research on this.
    And he actually bought me lunch due to the fact that I found it for him…
    lol. So allow me to reword this…. Thanks for the meal!! But yeah,
    thanx for spending some time to talk about this subject here on your
    internet site.

  15. Hi would you mind stating which blog platform you’re working
    with? I’m planning to start my own blog soon but I’m having a tough time selecting between BlogEngine/Wordpress/B2evolution and Drupal.
    The reason I ask is because your design seems different then most blogs and I’m looking for
    something unique. P.S Apologies for getting
    off-topic but I had to ask!

  16. Howdy, I think your site could be having internet browser compatibility problems.
    When I take a look at your site in Safari, it looks fine however, if opening in Internet
    Explorer, it has some overlapping issues. I merely wanted to provide you with a quick heads up!
    Apart from that, great website!

  17. I don’t even know the way I stopped up here, but I believed this submit was good.
    I do not recognize who you might be but definitely you’re
    going to a famous blogger for those who are not already.

    Cheers!

  18. Howdy just wanted to give you a brief heads up and let you know
    a few of the images aren’t loading correctly. I’m not sure why but
    I think its a linking issue. I’ve tried it in two different web browsers and both show the same outcome.

Leave a Reply

Your email address will not be published. Required fields are marked *

Back To Top