<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>toggle &#8211; stoimen&#039;s web log</title>
	<atom:link href="/tag/toggle/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>on web development</description>
	<lastBuildDate>Tue, 13 Feb 2018 08:18:15 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.0.3</generator>
	<item>
		<title>Toggle the visibility with jQuery</title>
		<link>/2009/11/30/toggle-the-visibility-with-jquery/</link>
		<comments>/2009/11/30/toggle-the-visibility-with-jquery/#comments</comments>
		<pubDate>Mon, 30 Nov 2009 19:24:25 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[micro tutorial]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[toggle]]></category>
		<category><![CDATA[visibility]]></category>

		<guid isPermaLink="false">/?p=817</guid>
		<description><![CDATA[When it comes to quick JavaScriopt effects one of the most common is to hide and show different elements in the DOM. That occurs in almost every site. If there&#8217;s a dynamic menu, there&#8217;s for sure attached mouse event that shows/hides some sub menus and so on. Of course you can achieve this in both &#8230; <a href="/2009/11/30/toggle-the-visibility-with-jquery/" class="more-link">Continue reading <span class="screen-reader-text">Toggle the visibility with jQuery</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2009/07/09/jquery-datepicker-persist-defaultdate/" rel="bookmark" title="jQuery datepicker persist defaultDate">jQuery datepicker persist defaultDate </a></li>
<li><a href="/2009/07/08/jquery-check-for-element-visibility/" rel="bookmark" title="jQuery check for element visibility">jQuery check for element visibility </a></li>
<li><a href="/2010/01/08/jquery-vs-pure-javascript/" rel="bookmark" title="jQuery vs. pure JavaScript">jQuery vs. pure JavaScript </a></li>
<li><a href="/2009/07/29/cancel-bubbling-on-element-click-with-jquery/" rel="bookmark" title="cancel bubbling on element click with jQuery">cancel bubbling on element click with jQuery </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p>When it comes to quick JavaScriopt effects one of the most common is to hide and show different elements in the DOM. That occurs in almost every site. If there&#8217;s a dynamic menu, there&#8217;s for sure attached mouse event that shows/hides some sub menus and so on.</p>
<p>Of course you can achieve this in both jQuery and pure JavaScript approaches. If you use JS it&#8217;s something like that;</p>
<blockquote>
<pre>document.getElementById('element_id').style.display = 'block';
document.getElementById('element_id').style.display = 'none';</pre>
</blockquote>
<p>where the first row shows how to show an element, and the second one how to hide it in turn.<span id="more-817"></span></p>
<h2>The jQuery way!</h2>
<p>With jQuery of course that comes with ease.</p>
<blockquote>
<pre>$('#element_id').show();
$('#element_id').hide();</pre>
</blockquote>
<h2>The problem is&#8230;</h2>
<p>when you&#8217;d like to change the visibility with only one click over one element.</p>
<p>Let&#8217;s assume you&#8217;ve one A tag and on click you show a DIV element. In turn when the DIV is already visible, on click over the same A tag you&#8217;d like to hide the DIV.</p>
<h2>How to make this the hard way?</h2>
<blockquote>
<pre>$('#a_tag_id').click(function() {
    if ( $('#div_id').length &gt; 0 )
        $('#div_id').hide();
    else
        $('#div_id').show();
});</pre>
</blockquote>
<p>The good news is that you can toggle the visibility with the $.toggle function, which is built-in in jQuery. The same functionality, shown above you can do, simply by that:</p>
<blockquote>
<pre>$('#a_tag_id').click(function() {
   $('#div_id').toggle();
});</pre>
</blockquote>
<p>And that is pretty simple and clear.</p>
<p><em><strong>Note</strong></em> that if you&#8217;d like to change the CSS visibility property that toggle function wont work. The toggle is useful only for changing the display CSS property.</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2009/07/09/jquery-datepicker-persist-defaultdate/" rel="bookmark" title="jQuery datepicker persist defaultDate">jQuery datepicker persist defaultDate </a></li>
<li><a href="/2009/07/08/jquery-check-for-element-visibility/" rel="bookmark" title="jQuery check for element visibility">jQuery check for element visibility </a></li>
<li><a href="/2010/01/08/jquery-vs-pure-javascript/" rel="bookmark" title="jQuery vs. pure JavaScript">jQuery vs. pure JavaScript </a></li>
<li><a href="/2009/07/29/cancel-bubbling-on-element-click-with-jquery/" rel="bookmark" title="cancel bubbling on element click with jQuery">cancel bubbling on element click with jQuery </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2009/11/30/toggle-the-visibility-with-jquery/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
