<?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>jQuery &#8211; Extreme Web Designs</title>
	<atom:link href="https://theextremewebdesigns.com/blog/category/jquery-tips-and-tricks/feed/" rel="self" type="application/rss+xml" />
	<link>https://theextremewebdesigns.com/blog</link>
	<description>Web Design and Web Development</description>
	<lastBuildDate>Mon, 14 Jul 2014 10:14:31 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.7.5</generator>
<site xmlns="com-wordpress:feed-additions:1">156673191</site>	<item>
		<title>Remove Single Or Multiple Attributes Using jQuery Examples</title>
		<link>https://theextremewebdesigns.com/blog/remove-single-or-multiple-attributes-using-jquery-examples/</link>
					<comments>https://theextremewebdesigns.com/blog/remove-single-or-multiple-attributes-using-jquery-examples/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Mon, 14 Jul 2014 10:14:31 +0000</pubDate>
				<category><![CDATA[Demos]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[jQuery Demos]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[jquery-demos]]></category>
		<category><![CDATA[jquery-snippets]]></category>
		<category><![CDATA[jquery-tips]]></category>
		<guid isPermaLink="false">https://theextremewebdesigns.com/blog/?p=3991</guid>

					<description><![CDATA[When working with different elements of a website, there might be times when you have come across different elements containing a single attribute or multiple attributes. These attributes can, in turn, consist of single or multiple properties. So in this article, I am going to share with you very easy way to get rid of [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>When working with different elements of a website, there might be times when you have come across different elements containing a single attribute or multiple attributes. These attributes can, in turn, consist of single or multiple properties. So in this article, I am going to share with you very easy way to get rid of either a single attribute or multiple attributes from any element of your choice using jQuery with easy to follow examples.</p>
<h2>How To Remove Single Or Multiple Attributes:</h2>
<p><div class="make_demo">

	<form action="https://theextremewebdesigns.com/blog/wp-content/themes/ewd_blog_2017/try_demo.php?post_id=4021" method="post" name="form1" target="_blank" id="form1">


	<input type="hidden" name="shortcode_content" id="shortcode_content" value="" />

        <div class="try_demo_btn_container">


            <button type="submit" name="sbt_make_demo" id="sbt_make_demo" class="btn-primary btn-try-demo">
                Try Demo
            </button>


        </div><!-- .try_demo_btn_container -->

    </form>
    </div>
     Let’s look at how to do this by means of examples. Assume that we have couple of div elements with attributes. We will see how to remove single &amp; multiple attributes from it.</p>
<h2>Examples:</h2>
<h3>Example 1: Remove single attribute from an element:</h3>
<p>In this example, we have a div with an attribute called “style”. This “style” attribute contains multiple properties such as “background-color” and “color”. We also have a button and when this button is clicked, we will remove the style attribute and the div will appear plain.</p>
<pre class="lang:xhtml decode:true">&lt;div id="my_div1" style="background-color: gold; color: darkgreen;"&gt;This is a div with a single "style" attribute.&lt;/div&gt;

&lt;input type="submit" name="sbt_remove_single_property" id="sbt_remove_single_property" value="Remove Style Attribute"&gt;

&lt;script type="text/javascript" language="javascript"&gt;

   $(document).ready(function () {

       $('#sbt_remove_single_property').on("click", function () {

           $('#my_div1').removeAttr('style');

       });

   });

&lt;/script&gt;</pre>
<h3>Example 2: Remove multiple attributes from an element:</h3>
<p>In this example, we have a div with an attribute called “style” and “class”. This “style” attribute contains multiple properties such as “background-color” and “color”. The “class” attribute contains multiple properties that affects the way this div is displayed even further. Next, we have a button and when this button is clicked, we will remove both the “style” and the “class” attributes and the div will appear plain.</p>
<pre class="lang:xhtml decode:true ">&lt;div id="my_div2" class="highlight" style="background-color: lightblue; color: purple;"&gt;This is a div with multiple attributes (style and class).&lt;/div&gt;

&lt;input type="submit" name="sbt_remove_multiple_properties" id="sbt_remove_multiple_properties" value="Remove Style and Class Attributes"&gt;

&lt;script type="text/javascript" language="javascript"&gt;

   $(document).ready(function () {

       $('#sbt_remove_multiple_properties').on("click", function () {

           $('#my_div2').removeAttr('style class');

       });

   });

&lt;/script&gt;</pre>
<div class="make_demo">

	<form action="https://theextremewebdesigns.com/blog/wp-content/themes/ewd_blog_2017/try_demo.php?post_id=4021" method="post" name="form1" target="_blank" id="form1">


	<input type="hidden" name="shortcode_content" id="shortcode_content" value="" />

        <div class="try_demo_btn_container">


            <button type="submit" name="sbt_make_demo" id="sbt_make_demo" class="btn-primary btn-try-demo">
                Try Demo
            </button>


        </div><!-- .try_demo_btn_container -->

    </form>
    </div>
    
<h3>Conclusion:</h3>
<p>So from the above example, we can conclude that we can remove a single attribute or multiple attributes from any element. <strong>To remove multiple attributes, simply specifying the attributes separated by space will suffice</strong>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://theextremewebdesigns.com/blog/remove-single-or-multiple-attributes-using-jquery-examples/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">4021</post-id>	</item>
		<item>
		<title>Remove Only One Inline Style Property With jQuery Examples</title>
		<link>https://theextremewebdesigns.com/blog/removing-single-inline-style-property-using-jquery/</link>
					<comments>https://theextremewebdesigns.com/blog/removing-single-inline-style-property-using-jquery/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Wed, 25 Sep 2013 19:05:20 +0000</pubDate>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[jquery-demos]]></category>
		<category><![CDATA[jquery-snippets]]></category>
		<category><![CDATA[jquery-tips]]></category>
		<guid isPermaLink="false">https://theextremewebdesigns.com/blog/?p=3959</guid>

					<description><![CDATA[At some point of time or the other, you may have come across an element that has inline styles applied to it with multiple properties and their respective values. So do you know of a way to remove a specific property and retain the rest? If not, this article is for you. In this article, [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>At some point of time or the other, you may have come across an element that has inline styles applied to it with multiple properties and their respective values. So do you know of a way to <strong>remove a specific property</strong> and retain the rest? If not, this article is for you. In this article, I am going to share share a very easy way to do so. Follow along for more info.</p>
<p><span id="more-3959"></span></p>
<h2>How to remove a specifc inline property using jQuery</h2>
<div class="make_demo">

	<form action="https://theextremewebdesigns.com/blog/wp-content/themes/ewd_blog_2017/try_demo.php?post_id=3959" method="post" name="form1" target="_blank" id="form1">


	<input type="hidden" name="shortcode_content" id="shortcode_content" value="" />

        <div class="try_demo_btn_container">


            <button type="submit" name="sbt_make_demo" id="sbt_make_demo" class="btn-primary btn-try-demo">
                Try Demo
            </button>


        </div><!-- .try_demo_btn_container -->

    </form>
    </div>
    
<p>Let&#8217;s look at how to do this by means of an example. Assume that you have a div with ID &#8220;<strong>my_div</strong>&#8220;. This div has four properties such as width, height and background color and color applied inline to it. So it would look something like this:</p>
<pre class="lang:xhtml decode:true">&lt;div id="my_div" style="width: 50%; height: 50%; background-color:red; color:green;"&gt;
This is my div with a background
&lt;/div&gt;</pre>
<p>Now you would like to remove the background-color property alone and leave the other properties with their respective values as it is. In order to so, here&#8217;s what you would need to do:</p>
<pre class="lang:xhtml decode:true">$('#my_div').css("background-color", "");</pre>
<p>Considering the above example, if you just wanted to remove the height property of the div and retain the others as they are, here&#8217;s what needs to be done:</p>
<pre class="lang:xhtml decode:true">$('#my_div').css("height", "");</pre>
<p>So you see, it&#8217;s very easy to remove any specific property along with its value applied to any element when inline styles are applied to the element.</p>
<p><strong>NOTE:</strong></p>
<p>One thing to remember is that removing any property in the way indicated above, will not overwrite the stylesheet itself. That means, your styles will be intact in the stylesheet. The targeted inline property will be just removed from the element in the DOM.</p>
<div class="make_demo">

	<form action="https://theextremewebdesigns.com/blog/wp-content/themes/ewd_blog_2017/try_demo.php?post_id=3959" method="post" name="form1" target="_blank" id="form1">


	<input type="hidden" name="shortcode_content" id="shortcode_content" value="" />

        <div class="try_demo_btn_container">


            <button type="submit" name="sbt_make_demo" id="sbt_make_demo" class="btn-primary btn-try-demo">
                Try Demo
            </button>


        </div><!-- .try_demo_btn_container -->

    </form>
    </div>
    
<h5>That&#8217;s it!</h5>
<p>Has this post helped you? Feel free to suggest by commenting below.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://theextremewebdesigns.com/blog/removing-single-inline-style-property-using-jquery/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">3959</post-id>	</item>
		<item>
		<title>Detect Click Outside Element Using jQuery</title>
		<link>https://theextremewebdesigns.com/blog/detecting-click-outside-element-jquery/</link>
					<comments>https://theextremewebdesigns.com/blog/detecting-click-outside-element-jquery/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Sat, 03 Aug 2013 19:05:58 +0000</pubDate>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[jquery-demos]]></category>
		<category><![CDATA[jquery-snippets]]></category>
		<category><![CDATA[jquery-tips]]></category>
		<guid isPermaLink="false">https://theextremewebdesigns.com/blog/?p=3931</guid>

					<description><![CDATA[Ever wanted to detect click outside an element using jQuery? In this article, I am going to share an easy way to do it and you can apply the same procedure for detecting click outside elements such as div, form, unordered list, etc. Also try the demo to see how it works in real time. [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Ever wanted to <em><strong>detect click outside an element using jQuery</strong></em>? In this article, I am going to share an easy way to do it and you can apply the same procedure for detecting click outside elements such as div, form, unordered list, etc. Also try the demo to see how it works in real time.<span id="more-3931"></span></p>
<h2>How To Detect Click Outside An Element Using jQuery</h2>
<div class="make_demo">

	<form action="https://theextremewebdesigns.com/blog/wp-content/themes/ewd_blog_2017/try_demo.php?post_id=3931" method="post" name="form1" target="_blank" id="form1">


	<input type="hidden" name="shortcode_content" id="shortcode_content" value="" />

        <div class="try_demo_btn_container">


            <button type="submit" name="sbt_make_demo" id="sbt_make_demo" class="btn-primary btn-try-demo">
                Try Demo
            </button>


        </div><!-- .try_demo_btn_container -->

    </form>
    </div>
    
<p>Let&#8217;s assume that we have a div with ID &#8220;my_div&#8221;. Now we would like to show an alert when we click inside this div and another alert when we click outside this div. Here&#8217;s an example of how it can be done:</p>
<pre class="lang:xhtml decode:true crayon-selected">&lt;style type="text/css"&gt;
#my_div {
	background-color: #FC9;
	padding: 25px;
	border: 1px solid #F60;
}
&lt;/style&gt;

&lt;div id="my_div" class="my_class"&gt;This is some content. Click inside this div once and click outside this div to see the alerts.&lt;/div&gt;

&lt;script type="text/javascript"&gt;
$(document).ready(function() {

	$('#my_div').click(function(event){		
		var id = $(this).attr('id');		
		alert('You clicked INSIDE the Div with ID #'+ id);		
		event.stopPropagation();		
	});

	$('html').click(function() {		
		alert('You clicked OUTSIDE the div');		
	});
});
&lt;/script&gt;</pre>
<p>First, we target the <strong>div</strong> and we attach a click event to it so that we can see an alert when it is clicked upon. To show an alert when we click outside the div, we target the <strong>html</strong> tag.</p>
<div class="make_demo">

	<form action="https://theextremewebdesigns.com/blog/wp-content/themes/ewd_blog_2017/try_demo.php?post_id=3931" method="post" name="form1" target="_blank" id="form1">


	<input type="hidden" name="shortcode_content" id="shortcode_content" value="" />

        <div class="try_demo_btn_container">


            <button type="submit" name="sbt_make_demo" id="sbt_make_demo" class="btn-primary btn-try-demo">
                Try Demo
            </button>


        </div><!-- .try_demo_btn_container -->

    </form>
    </div>
    
<h5>Your Turn!</h5>
<p>Do you know of any other ways of <em><strong>detecting click outside an element using jQuery</strong></em>? Feel free to suggest by commenting below.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://theextremewebdesigns.com/blog/detecting-click-outside-element-jquery/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">3931</post-id>	</item>
		<item>
		<title>jQuery Checkbox Check / Uncheck Examples</title>
		<link>https://theextremewebdesigns.com/blog/check-uncheck-checkbox-using-jquery/</link>
					<comments>https://theextremewebdesigns.com/blog/check-uncheck-checkbox-using-jquery/#comments</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Sun, 09 Jun 2013 19:05:39 +0000</pubDate>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[jquery-demos]]></category>
		<category><![CDATA[jquery-snippets]]></category>
		<category><![CDATA[jquery-tips]]></category>
		<guid isPermaLink="false">https://theextremewebdesigns.com/blog/?p=3881</guid>

					<description><![CDATA[Among all the form elements, the check box is one of the essential element that we get to work with, almost every day.  So at one point of time or the other, it might be useful to check a checkbox or uncheck a checkbox dynamically using jQuery. So in this article, I am going to [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Among all the form elements, the check box is one of the essential element that we get to work with, almost every day.  So at one point of time or the other, it might be useful to check a <em><strong>checkbox or uncheck a checkbox dynamically using jQuery</strong></em>. So in this article, I am going to share very easy ways to use the checked property to check and uncheck checkbox. Easy examples with demos follow, so it&#8217;s super easy to follow along.</p>
<p><span id="more-3881"></span></p>
<h2>How To Check Or Uncheck Checkbox Using jQuery</h2>
<div class="make_demo">

	<form action="https://theextremewebdesigns.com/blog/wp-content/themes/ewd_blog_2017/try_demo.php?post_id=3881" method="post" name="form1" target="_blank" id="form1">


	<input type="hidden" name="shortcode_content" id="shortcode_content" value="" />

        <div class="try_demo_btn_container">


            <button type="submit" name="sbt_make_demo" id="sbt_make_demo" class="btn-primary btn-try-demo">
                Try Demo
            </button>


        </div><!-- .try_demo_btn_container -->

    </form>
    </div>
    
<p>Let&#8217;s assume that we have a checkboxe with ID &#8220;mycheckbox&#8221;. Now let&#8217;s see how to check and uncheck this checkbox when two different buttons are clicked by means of examples.</p>
<h3>Here&#8217;s the common HTML for the following examples:</h3>
<pre class="lang:xhtml decode:true">&lt;input name="mycheckbox" type="checkbox" id="mycheckbox" /&gt; This is my checkbox

&lt;p&gt;	
&lt;input type="submit" name="sbt_check" id="sbt_check" value="Check Checkbox"&gt;

&lt;input type="submit" name="sbt_uncheck" id="sbt_uncheck" value="Uncheck Checkbox"&gt;

&lt;/p&gt;</pre>
<h3>Example 1: Check a Checkbox when a button is clicked</h3>
<pre class="lang:xhtml decode:true">	//Check a checkbox
	$('#sbt_check').on("click", function(e){		

		$('#mycheckbox').prop('checked', true);

		e.preventDefault();

	});</pre>
<h3>Example 2: Uncheck a Checkbox when a button is clicked</h3>
<pre class="lang:xhtml decode:true">	//Uncheck a checkbox
	$('#sbt_uncheck').on("click", function(e){		

		$('#mycheckbox').prop('checked', false);

		e.preventDefault();

	});</pre>
<div class="make_demo">

	<form action="https://theextremewebdesigns.com/blog/wp-content/themes/ewd_blog_2017/try_demo.php?post_id=3881" method="post" name="form1" target="_blank" id="form1">


	<input type="hidden" name="shortcode_content" id="shortcode_content" value="" />

        <div class="try_demo_btn_container">


            <button type="submit" name="sbt_make_demo" id="sbt_make_demo" class="btn-primary btn-try-demo">
                Try Demo
            </button>


        </div><!-- .try_demo_btn_container -->

    </form>
    </div>
    
<h5>Simple, isn&#8217;t it?</h5>
<p>Do you know of any other ways to <em><strong>check or uncheck a checkbox using jQuery</strong></em>? Feel free to suggest by commenting below.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://theextremewebdesigns.com/blog/check-uncheck-checkbox-using-jquery/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">3881</post-id>	</item>
		<item>
		<title>jQuery Check If Div Is Empty Examples</title>
		<link>https://theextremewebdesigns.com/blog/jquery-check-if-div-is-empty-examples/</link>
					<comments>https://theextremewebdesigns.com/blog/jquery-check-if-div-is-empty-examples/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Mon, 20 May 2013 19:05:09 +0000</pubDate>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[jquery-demos]]></category>
		<category><![CDATA[jquery-snippets]]></category>
		<category><![CDATA[jquery-tips]]></category>
		<guid isPermaLink="false">https://theextremewebdesigns.com/blog/?p=3873</guid>

					<description><![CDATA[When working with Divs and jQuery, there might have been a situation when you needed to know dynamically if any given div contains any content at all or not. Based upon this, you might want to trigger an action. So in this article, I am going to share easy ways to find out if a [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>When working with Divs and jQuery, there might have been a situation when you needed to know dynamically if any given div contains any content at all or not. Based upon this, you might want to trigger an action. So in this article, I am going to share easy ways to <em><strong>find out if a Div is empty or not</strong></em> by means of easy to follow examples. Check out the Demo to see how it works in real time.</p>
<h2>How To Check If Div Is Empty Using jQuery</h2>
<div class="make_demo">

	<form action="https://theextremewebdesigns.com/blog/wp-content/themes/ewd_blog_2017/try_demo.php?post_id=3873" method="post" name="form1" target="_blank" id="form1">


	<input type="hidden" name="shortcode_content" id="shortcode_content" value="" />

        <div class="try_demo_btn_container">


            <button type="submit" name="sbt_make_demo" id="sbt_make_demo" class="btn-primary btn-try-demo">
                Try Demo
            </button>


        </div><!-- .try_demo_btn_container -->

    </form>
    </div>
    
<p>Let&#8217;s assume that we have three  divs with IDs &#8216;my_div1&#8217;, &#8216;my_div2&#8217; and &#8216;my_div3&#8217;.</p>
<p>&#8216;my_div1&#8217; will not contain any content,  &#8216;my_div2&#8217; will have content in it and  &#8216;my_div3&#8217; will contain only a single space and no actual content. Now we will check if there are any contents in these div or not using jQuery</p>
<h3>Here is the common HTML for all the following examples:</h3>
<pre class="lang:xhtml decode:true">	&lt;div id="my_div1"&gt;&lt;/div&gt;

	&lt;div id="my_div2"&gt;This is the second div and it has some content. Div 1 is located above and it is invisible as it does not have any content. But you should be able to see the purple borders on the div 1 above. There is another div with red border below.&lt;/div&gt;    

	&lt;div id="my_div3"&gt; &lt;/div&gt;    

&lt;br&gt;

&lt;input type="submit" name="sbt_check1" id="sbt_check1" value="Check if Div 1 is empty"&gt;

&lt;input type="submit" name="sbt_check2" id="sbt_check2" value="Check if Div 2 is empty"&gt;

&lt;input type="submit" name="sbt_check3" id="sbt_check3" value="Check if Div 3 is empty"&gt;

&lt;input type="submit" name="sbt_check4" id="sbt_check4" value="Check if Div 3 is empty After Applying Trim"&gt;</pre>
<h3>Example 1:  Check if div is empty and alert the status when a button is clicked</h3>
<pre class="lang:xhtml decode:true">&lt;script type="text/javascript"&gt;

$(document).ready(function(){

	$('#sbt_check1').on("click", function(e){		

		if( $('#my_div1').is(':empty') ) 
			{	
			alert('Div 1 is Empty!');
		}
		else
		{
			alert('Div 1 is NOT Empty!');			
		}

		e.preventDefault();

	});

	$('#sbt_check2').on("click", function(e){

		if( $('#my_div2').is(':empty') ) 
		{	
			alert('Div 2 is Empty!');
		}
		else
		{
			alert('Div 2 is NOT Empty!');			
		}					

		e.preventDefault();

	});

	$('#sbt_check3').on("click", function(e){

		if( $('#my_div3').is(':empty') ) 
		{	
			alert('Div 3 is Empty!');
		}
		else
		{
			alert('Div 3 is NOT Empty!');			
		}					

		e.preventDefault();

	});		

});

&lt;/script&gt;</pre>
<h3>Results of Example 1:</h3>
<p>When you run the above code and click on the first button, you will see an alert that says that my_div1 is <strong>Empty</strong>. This is correct as there is no content in it.</p>
<p>When you click on the second button, you will see an alert that says that my_div2 is <strong>Not Empty</strong>. This is correct as there is some custom content in it.</p>
<p>When you click on the third button, you will see an alert that says that my_div3 is <strong>NOT Empty</strong>. Well, as far as we can see, there is no content in it. Yet, the alert says that my_div3 is <strong>NOT empty</strong>. Why? Are you surprised why? Well, here&#8217;s the reason. &#8216;my_div3&#8217; does not contain any actual text or any other HTML content BUT it does contain a &#8220;space&#8221; or &#8220;white space&#8221;. Now even a space is considered as the content of a div. And for this reason, we see the alert that it is <strong>NOT empty</strong>. So how to fix this? Our next example will solve this situation.</p>
<h3>Example 2:  Apply trim to a div&#8217;s content and then check if it is empty or not</h3>
<pre class="lang:xhtml decode:true">	$('#sbt_check4').on("click", function(e){

		//Get the HTML content of the div
		var div3_content = $('#my_div3').html();

		//Apply trim to the retrieved HTML content and then perform the check		
		if( $.trim(div3_content) == '' ) 
		{	
			alert('Div 3 is Empty!');
		}
		else
		{
			alert('Div 3 is NOT Empty!');			
		}					

		e.preventDefault();

	});</pre>
<p>In the above code, we first retrieve the HTML content of the &#8220;my_div3&#8221; . This will remove any spaces in the retrieved content. Now we check this to see if it is empty or not. This will give us the correct output.</p>
<div class="make_demo">

	<form action="https://theextremewebdesigns.com/blog/wp-content/themes/ewd_blog_2017/try_demo.php?post_id=3873" method="post" name="form1" target="_blank" id="form1">


	<input type="hidden" name="shortcode_content" id="shortcode_content" value="" />

        <div class="try_demo_btn_container">


            <button type="submit" name="sbt_make_demo" id="sbt_make_demo" class="btn-primary btn-try-demo">
                Try Demo
            </button>


        </div><!-- .try_demo_btn_container -->

    </form>
    </div>
    
<h5>Your Turn!</h5>
<p>Do you know of any other ways to <em><strong>check if a div is empty or not using jQuery</strong></em>? Feel free to suggest by commenting below.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://theextremewebdesigns.com/blog/jquery-check-if-div-is-empty-examples/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">3873</post-id>	</item>
		<item>
		<title>jQuery Change Select Options Examples</title>
		<link>https://theextremewebdesigns.com/blog/jquery-change-select-list-options/</link>
					<comments>https://theextremewebdesigns.com/blog/jquery-change-select-list-options/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Sun, 19 May 2013 19:05:17 +0000</pubDate>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[jquery-demos]]></category>
		<category><![CDATA[jquery-snippets]]></category>
		<category><![CDATA[jquery-tips]]></category>
		<guid isPermaLink="false">https://theextremewebdesigns.com/blog/?p=3868</guid>

					<description><![CDATA[Form element manipulation using jQuery can be of immense help when working with forms. As such, it is desirable to know if the options of a select dropdown list can be changed or not. Well, the answer is yes! We can dynamically change the options of a select dropdown. We can remove existing options (if [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Form element manipulation using jQuery can be of immense help when working with forms. As such, it is desirable to know if the options of a select dropdown list can be changed or not. Well, the answer is yes! We can dynamically change the options of a select dropdown. We can remove existing options (if any) and then add new options dynamically. So this article covers the simple ways in which we can <em><strong>change or refresh the options of a select list using jQuery</strong></em>.</p>
<p><span id="more-3868"></span></p>
<h2>How To Change Select Options Using jQuery</h2>
<div class="make_demo">

	<form action="https://theextremewebdesigns.com/blog/wp-content/themes/ewd_blog_2017/try_demo.php?post_id=3868" method="post" name="form1" target="_blank" id="form1">


	<input type="hidden" name="shortcode_content" id="shortcode_content" value="" />

        <div class="try_demo_btn_container">


            <button type="submit" name="sbt_make_demo" id="sbt_make_demo" class="btn-primary btn-try-demo">
                Try Demo
            </button>


        </div><!-- .try_demo_btn_container -->

    </form>
    </div>
    
<p>Let&#8217;s assume that we have a select dropdown list that contains the state &#8220;Texas&#8221; as one of  the values in it. Now we will see different examples that show us how to remove this existing value and add new ones to it.</p>
<h3>Here is the common HTML code for all the following examples:</h3>
<pre class="lang:xhtml decode:true">&lt;label for="states"&gt;States&lt;/label&gt;
&lt;select name="states" id="states"&gt;
  &lt;option value="Texas"&gt;Texas&lt;/option&gt;
&lt;/select&gt;

&lt;input type="submit" name="sbt_change_single" id="sbt_change_single" value="Change options with Single Option"&gt;

&lt;input type="submit" name="sbt_change_array" id="sbt_change_array" value="Change options with Array Options"&gt;</pre>
<h3>Example 1: Remove existing select dropdown list options and add a single new option to it</h3>
<pre class="lang:xhtml decode:true">&lt;script type="text/javascript"&gt;

$(document).ready(function(){	

	$('#sbt_change_single').on("click", function(e){

		//Remove all existing options of the dropdown list
		$("#states").empty();			

		//Prepare the new option
		var new_option = $('&lt;option&gt;&lt;/option&gt;').attr("value", "AL").text("Alabama");

		//Add the new option to the recently cleared select dropdown
		$("#states").append(new_option);

		e.preventDefault();

	});

});

&lt;/script&gt;</pre>
<p>In the above example, when the first button is clicked, we can see that the exiting option is removed completely and the new option is added. This method is desirable when you wish to add only one new option. If you want to add multiple options, then take a look at the example below.</p>
<h3>Example 2: Remove existing select dropdown list options and add multiple new options to it from an array</h3>
<pre class="lang:xhtml decode:true">&lt;script type="text/javascript"&gt;

$(document).ready(function(){	

	$('#sbt_change_array').on("click", function(e){

		//Remove all existing options of the dropdown list
		$("#states").empty();			

		//Prepare the multiple new options
		var new_states = {"Illinois": "IL",
						  "California": "CA",
						  "New Jersey": "NJ"
						};

		//Add all options to the recently cleared select dropdown
		$.each(new_states, function(key, value) {

		  $("#states").append($("&lt;option&gt;&lt;/option&gt;").attr("value", value).text(key));

		});	

		e.preventDefault();

	});

});

&lt;/script&gt;</pre>
<p>In the above example, when the second button is clicked, you can see that all the existing options of the dropdown are removed and new options from the array are added.</p>
<div class="make_demo">

	<form action="https://theextremewebdesigns.com/blog/wp-content/themes/ewd_blog_2017/try_demo.php?post_id=3868" method="post" name="form1" target="_blank" id="form1">


	<input type="hidden" name="shortcode_content" id="shortcode_content" value="" />

        <div class="try_demo_btn_container">


            <button type="submit" name="sbt_make_demo" id="sbt_make_demo" class="btn-primary btn-try-demo">
                Try Demo
            </button>


        </div><!-- .try_demo_btn_container -->

    </form>
    </div>
    
<h5>Simple, isn&#8217;t it?</h5>
<p>Do you know of any other ways to <em><strong>change options of a select dropdown list using jQuery</strong></em>? Feel free to suggest by commenting below.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://theextremewebdesigns.com/blog/jquery-change-select-list-options/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">3868</post-id>	</item>
		<item>
		<title>jQuery Find Value In Array Examples</title>
		<link>https://theextremewebdesigns.com/blog/jquery-search-array-for-value/</link>
					<comments>https://theextremewebdesigns.com/blog/jquery-search-array-for-value/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Sat, 18 May 2013 19:05:18 +0000</pubDate>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[jquery-demos]]></category>
		<category><![CDATA[jquery-snippets]]></category>
		<category><![CDATA[jquery-tips]]></category>
		<guid isPermaLink="false">https://theextremewebdesigns.com/blog/?p=3864</guid>

					<description><![CDATA[Talking about arrays in jQuery, it can be really helpful to know if a value exists in an array or not. That said, in this article, I am going to share examples on how to find if a specific value exists in an array or not using jQuery. Try the demo to see how it [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Talking about arrays in jQuery, it can be really helpful to know if a value exists in an array or not. That said, in this article, I am going to share examples on how to <strong>find if a specific value exists in an array or not using jQuery</strong>. Try the demo to see how it works in real time.</p>
<p><span id="more-3864"></span></p>
<h2>How To Find If A Value Exists In Array Or Not Using jQuery</h2>
<div class="make_demo">

	<form action="https://theextremewebdesigns.com/blog/wp-content/themes/ewd_blog_2017/try_demo.php?post_id=3864" method="post" name="form1" target="_blank" id="form1">


	<input type="hidden" name="shortcode_content" id="shortcode_content" value="" />

        <div class="try_demo_btn_container">


            <button type="submit" name="sbt_make_demo" id="sbt_make_demo" class="btn-primary btn-try-demo">
                Try Demo
            </button>


        </div><!-- .try_demo_btn_container -->

    </form>
    </div>
    
<p>Let&#8217;s assume that we have an array of fruits. Now we would like to search if this array contains a fruit of our choice. Let&#8217;s see how this can be done.</p>
<h3>Example: Check if a value exists in an array when a button is clicked</h3>
<pre class="lang:xhtml decode:true">&lt;input type="submit" name="sbt_check" id="sbt_check" value="Check if 'mango' exists in array"&gt;

&lt;input type="submit" name="sbt_check_straw" id="sbt_check_straw" value="Check if 'strawberry' exists in array"&gt;

&lt;script type="text/javascript"&gt;

$(document).ready(function(){

var fruits_array = new Array('grapes', 'apple', 'mango');	

$('#sbt_check').on("click", function(e){

	var search_for = 'mango';

	if($.inArray(search_for, fruits_array) &gt; -1)
	{
		alert("Mango exists in the array");
	}
	else
	{
		alert("Mange does not exist in array");
	}

	e.preventDefault();

});

$('#sbt_check_straw').on("click", function(e){

	var search_for = 'strawberry';

	if($.inArray(search_for, fruits_array) &gt; -1)
	{
		alert("Strawberry exists in the array");
	}
	else
	{
		alert("Strawberry does not exist in array");
	}

	e.preventDefault();

});

});

&lt;/script&gt;</pre>
<p>In the above example, when the first button is clicked, the value &#8216;mango&#8217; is searched for and the result is displayed. When the second button is clicked, the value &#8216;strawberry&#8217; is searched for and the result is displayed.</p>
<div class="make_demo">

	<form action="https://theextremewebdesigns.com/blog/wp-content/themes/ewd_blog_2017/try_demo.php?post_id=3864" method="post" name="form1" target="_blank" id="form1">


	<input type="hidden" name="shortcode_content" id="shortcode_content" value="" />

        <div class="try_demo_btn_container">


            <button type="submit" name="sbt_make_demo" id="sbt_make_demo" class="btn-primary btn-try-demo">
                Try Demo
            </button>


        </div><!-- .try_demo_btn_container -->

    </form>
    </div>
    
<h5>Simple, isn&#8217;t it?</h5>
<p>Do you know of any other ways to find value in array of objects using jQuery? Feel free to suggest by commenting below.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://theextremewebdesigns.com/blog/jquery-search-array-for-value/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">3864</post-id>	</item>
		<item>
		<title>JavaScript: Count Occurrences Of String In String Examples</title>
		<link>https://theextremewebdesigns.com/blog/counting-occurrences-of-word-in-string/</link>
					<comments>https://theextremewebdesigns.com/blog/counting-occurrences-of-word-in-string/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Tue, 14 May 2013 19:05:46 +0000</pubDate>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[jquery-demos]]></category>
		<category><![CDATA[jquery-snippets]]></category>
		<category><![CDATA[jquery-tips]]></category>
		<guid isPermaLink="false">https://theextremewebdesigns.com/blog/?p=3838</guid>

					<description><![CDATA[At some point or the other, it might be useful to count the number of occurrences of a specific word or a string in another string using JavaScript. In this article, I am going to share very easy example to do just that with the help of easy to follow examples. Read on to find [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>At some point or the other, it might be useful to count the number of occurrences of a specific word or a string in another string using JavaScript. In this article, I am going to share very easy example to do just that with the help of easy to follow examples. Read on to find out more.</p>
<p><span id="more-3838"></span></p>
<h2>How To Count Occurrences In String Using JavaScript</h2>
<div class="make_demo">

	<form action="https://theextremewebdesigns.com/blog/wp-content/themes/ewd_blog_2017/try_demo.php?post_id=3838" method="post" name="form1" target="_blank" id="form1">


	<input type="hidden" name="shortcode_content" id="shortcode_content" value="" />

        <div class="try_demo_btn_container">


            <button type="submit" name="sbt_make_demo" id="sbt_make_demo" class="btn-primary btn-try-demo">
                Try Demo
            </button>


        </div><!-- .try_demo_btn_container -->

    </form>
    </div>
    
<p>Let&#8217;s look at how to do this with an example. Consider that we have a string that says: <strong>&#8220;This is a string.&#8221;</strong>. Now we want to find out the number of times the word <strong>&#8220;is&#8221;</strong> has repeated in that string. So here&#8217;s how it can be done in the most simplest way:</p>
<h3>Example:</h3>
<pre class="lang:xhtml decode:true">&lt;p&gt;The string that needs to be searched in is: &lt;strong&gt;"This is a string."&lt;/strong&gt;. So this is our Haystack.&lt;/p&gt;
&lt;p&gt;We want to search fo the word &lt;strong&gt;"is"&lt;/strong&gt;. So this is our Needle.&lt;/p&gt;
&lt;p&gt;You should see an alert as soon as the page loads.&lt;/p&gt;

&lt;script type="text/javascript"&gt;
var temp = "This is a string.";
// the g in the regular expression says to search the whole string 
// rather than just find the first occurrence
var count = temp.match(/is/g);  
alert('The word "is" is repeated ' + count.length + ' times.');
&lt;/script&gt;</pre>
<div class="make_demo">

	<form action="https://theextremewebdesigns.com/blog/wp-content/themes/ewd_blog_2017/try_demo.php?post_id=3838" method="post" name="form1" target="_blank" id="form1">


	<input type="hidden" name="shortcode_content" id="shortcode_content" value="" />

        <div class="try_demo_btn_container">


            <button type="submit" name="sbt_make_demo" id="sbt_make_demo" class="btn-primary btn-try-demo">
                Try Demo
            </button>


        </div><!-- .try_demo_btn_container -->

    </form>
    </div>
    
<h5>Simple, isn&#8217;t it?</h5>
<p>Do you know of any other ways to count the number of times a string or a word is repeated in another string using JavaScript? Feel free to suggest by commenting below.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://theextremewebdesigns.com/blog/counting-occurrences-of-word-in-string/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">3838</post-id>	</item>
		<item>
		<title>Selecting First Element Of Type Using :first-of-type Selector in jQuery</title>
		<link>https://theextremewebdesigns.com/blog/jquery-first-element-of-type/</link>
					<comments>https://theextremewebdesigns.com/blog/jquery-first-element-of-type/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Mon, 06 May 2013 19:05:50 +0000</pubDate>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[jquery-demos]]></category>
		<category><![CDATA[jquery-snippets]]></category>
		<category><![CDATA[jquery-tips]]></category>
		<guid isPermaLink="false">https://theextremewebdesigns.com/blog/?p=3818</guid>

					<description><![CDATA[The :first-of-type selector is another helpful selector in jQuery. It basically selects all elements that are the first among siblings of the same element name. That said, let&#8217;s take a look at quick examples on how to use it in real time to select any element that we need. How To Use the first-of-type Selector in [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>The <em><strong>:first-of-type selector</strong></em> is another helpful selector in jQuery. It basically selects all elements that are the first among siblings of the same element name. That said, let&#8217;s take a look at quick examples on how to use it in real time to select any element that we need.</p>
<p><span id="more-3818"></span></p>
<h2>How To Use the first-of-type Selector in jQuery</h2>
<div class="make_demo">

	<form action="https://theextremewebdesigns.com/blog/wp-content/themes/ewd_blog_2017/try_demo.php?post_id=3818" method="post" name="form1" target="_blank" id="form1">


	<input type="hidden" name="shortcode_content" id="shortcode_content" value="" />

        <div class="try_demo_btn_container">


            <button type="submit" name="sbt_make_demo" id="sbt_make_demo" class="btn-primary btn-try-demo">
                Try Demo
            </button>


        </div><!-- .try_demo_btn_container -->

    </form>
    </div>
    
<p>Let&#8217;s take a look at a quick example. The following is the HTML Source code used in the examples.</p>
<pre class="lang:xhtml decode:true">&lt;style type="text/css"&gt;
#my_div {
	background-color: #DBF0FF;
	border: 1px solid #06F;
}
.new_div {
	background-color: #FFDF9D;
	border: 1px solid #F90;
}
.purple {
	background-color: #9999FF;
	border: 1px solid #90F;
}
table td {
	border: 1px solid #CCC;
}

&lt;/style&gt;

&lt;div class="divs_container"&gt;

&lt;div id="my_div1"&gt;This is My Div 1.&lt;/div&gt;

&lt;div id="my_div2"&gt;This is My Div 2.&lt;/div&gt;

&lt;div id="my_div3"&gt;This is My Div 3.&lt;/div&gt;

&lt;div id="my_div4" class="new_div"&gt;This is My Div 4

&lt;span id="sp1"&gt;Span 1&lt;/span&gt;

&lt;p id="p1"&gt;Para 1&lt;/p&gt;

&lt;span id="sp2"&gt;Span 2&lt;/span&gt;

&lt;p id="p2"&gt;Para 2&lt;/p&gt;

&lt;p id="p3"&gt;Para 3&lt;/p&gt;

&lt;/div&gt;

&lt;br&gt;

&lt;table width="100%" border="1" cellspacing="1" cellpadding="1"&gt;
  &lt;tr&gt;
    &lt;td&gt;&amp;nbsp;&lt;/td&gt;
    &lt;td&gt;&amp;nbsp;&lt;/td&gt;
    &lt;td&gt;&amp;nbsp;&lt;/td&gt;
    &lt;td&gt;&amp;nbsp;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;&amp;nbsp;&lt;/td&gt;
    &lt;td&gt;&amp;nbsp;&lt;/td&gt;
    &lt;td&gt;&amp;nbsp;&lt;/td&gt;
    &lt;td&gt;&amp;nbsp;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;&amp;nbsp;&lt;/td&gt;
    &lt;td&gt;&amp;nbsp;&lt;/td&gt;
    &lt;td&gt;&amp;nbsp;&lt;/td&gt;
    &lt;td&gt;&amp;nbsp;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;&amp;nbsp;&lt;/td&gt;
    &lt;td&gt;&amp;nbsp;&lt;/td&gt;
    &lt;td&gt;&amp;nbsp;&lt;/td&gt;
    &lt;td&gt;&amp;nbsp;&lt;/td&gt;
  &lt;/tr&gt;
&lt;/table&gt;

&lt;/div&gt;

&lt;p&gt;	
  &lt;input type="submit" name="sbt_add1" id="sbt_add1" value="Add Class to First Div"&gt;

&lt;input type="submit" name="sbt_add2" id="sbt_add2" value="Add Class to First p"&gt;

&lt;input type="submit" name="sbt_add2" id="sbt_add3" value="Add Class to First span"&gt;&lt;br&gt;

&lt;input type="submit" name="sbt_add3" id="sbt_add4" value="Add Class to First td of Table"&gt;

&lt;/p&gt;</pre>
<h3>Example 1: Select first element of type div and adding custom class to it when a button is clicked</h3>
<pre class="lang:xhtml decode:true">	$('#sbt_add1').on("click", function(e){		

		$('.divs_container div:first-of-type').addClass('purple');

		e.preventDefault();

	});</pre>
<h3>Example 2: Select first element of type p and adding custom class to it when a button is clicked</h3>
<pre class="lang:xhtml decode:true">	$('#sbt_add2').on("click", function(e){			

		$('.divs_container p:first-of-type').addClass('purple');				

		e.preventDefault();

	});</pre>
<h3>Example 3: Select first element of type span and adding custom class to it when a button is clicked</h3>
<pre class="lang:xhtml decode:true">	$('#sbt_add3').on("click", function(e){			

		$('.divs_container span:first-of-type').addClass('purple');				

		e.preventDefault();

	});</pre>
<h3>Example 4: Select first element of type td and adding custom class to it when a button is clicked</h3>
<pre class="lang:xhtml decode:true">	$('#sbt_add4').on("click", function(e){		

		$('.divs_container table td:first-of-type').addClass('purple');

		e.preventDefault();

	});</pre>
<div class="make_demo">

	<form action="https://theextremewebdesigns.com/blog/wp-content/themes/ewd_blog_2017/try_demo.php?post_id=3818" method="post" name="form1" target="_blank" id="form1">


	<input type="hidden" name="shortcode_content" id="shortcode_content" value="" />

        <div class="try_demo_btn_container">


            <button type="submit" name="sbt_make_demo" id="sbt_make_demo" class="btn-primary btn-try-demo">
                Try Demo
            </button>


        </div><!-- .try_demo_btn_container -->

    </form>
    </div>
    
<h5>Simple, isn&#8217;t it?</h5>
<p>Do you know of any other ways to use the <em><strong>:first-of-type selector in jQuery</strong></em>? Feel free to suggest by commenting below.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://theextremewebdesigns.com/blog/jquery-first-element-of-type/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">3818</post-id>	</item>
		<item>
		<title>Selecting First Level Child Using :first-child Selector In jQuery</title>
		<link>https://theextremewebdesigns.com/blog/jquery-selector-first-child/</link>
					<comments>https://theextremewebdesigns.com/blog/jquery-selector-first-child/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Sun, 05 May 2013 19:05:51 +0000</pubDate>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[jquery-demos]]></category>
		<category><![CDATA[jquery-snippets]]></category>
		<category><![CDATA[jquery-tips]]></category>
		<guid isPermaLink="false">https://theextremewebdesigns.com/blog/?p=3812</guid>

					<description><![CDATA[If you have many elements in a web page but need to select only the first one among them and perform your operation on it, what would you do? If you don&#8217;t have an answer, then this article is for you. In this article, I am going to share very easy way to perform operations [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>If you have many elements in a web page but need to select only the first one among them and perform your operation on it, what would you do? If you don&#8217;t have an answer, then this article is for you. In this article, I am going to share very easy way to perform operations on the <em><strong>first level child</strong></em> of any desired element.  So read on to find out more.</p>
<p><span id="more-3812"></span></p>
<h2>How To Use :first-child Selector</h2>
<div class="make_demo">

	<form action="https://theextremewebdesigns.com/blog/wp-content/themes/ewd_blog_2017/try_demo.php?post_id=3812" method="post" name="form1" target="_blank" id="form1">


	<input type="hidden" name="shortcode_content" id="shortcode_content" value="" />

        <div class="try_demo_btn_container">


            <button type="submit" name="sbt_make_demo" id="sbt_make_demo" class="btn-primary btn-try-demo">
                Try Demo
            </button>


        </div><!-- .try_demo_btn_container -->

    </form>
    </div>
    
<p><strong><em>The first-child selector basically selects all elements that are the first child of their parent.</em></strong></p>
<p>Let&#8217;s take a look at a quick example. The following is the HTML Source code used in the examples.</p>
<pre class="lang:xhtml decode:true">&lt;div class="divs_container"&gt;

&lt;div id="my_div1"&gt;This is My Div 1.&lt;/div&gt;

&lt;div id="my_div2"&gt;This is My Div 2.&lt;/div&gt;

&lt;div id="my_div3"&gt;This is My Div 3.&lt;/div&gt;

&lt;div id="my_div4" class="new_div"&gt;This is My Div 4

&lt;p id="p1"&gt;Para 1&lt;/p&gt;

&lt;p id="p2"&gt;Para 2&lt;/p&gt;

&lt;p id="p3"&gt;Para 3&lt;/p&gt;

&lt;/div&gt;

&lt;br&gt;

&lt;table width="100%" border="1" cellspacing="1" cellpadding="1"&gt;
  &lt;tr&gt;
    &lt;td&gt;&amp;nbsp;&lt;/td&gt;
    &lt;td&gt;&amp;nbsp;&lt;/td&gt;
    &lt;td&gt;&amp;nbsp;&lt;/td&gt;
    &lt;td&gt;&amp;nbsp;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;&amp;nbsp;&lt;/td&gt;
    &lt;td&gt;&amp;nbsp;&lt;/td&gt;
    &lt;td&gt;&amp;nbsp;&lt;/td&gt;
    &lt;td&gt;&amp;nbsp;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;&amp;nbsp;&lt;/td&gt;
    &lt;td&gt;&amp;nbsp;&lt;/td&gt;
    &lt;td&gt;&amp;nbsp;&lt;/td&gt;
    &lt;td&gt;&amp;nbsp;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;&amp;nbsp;&lt;/td&gt;
    &lt;td&gt;&amp;nbsp;&lt;/td&gt;
    &lt;td&gt;&amp;nbsp;&lt;/td&gt;
    &lt;td&gt;&amp;nbsp;&lt;/td&gt;
  &lt;/tr&gt;
&lt;/table&gt;

&lt;/div&gt;

&lt;p&gt;	
  &lt;input type="submit" name="sbt_add1" id="sbt_add1" value="Add Class to First Div Child"&gt;

&lt;input type="submit" name="sbt_add2" id="sbt_add2" value="Add Class to First p child"&gt;&lt;br&gt;

&lt;input type="submit" name="sbt_add3" id="sbt_add3" value="Add Class to First child of Table"&gt;

&lt;br&gt;
&lt;input type="button" name="sbt_reset" id="sbt_reset" value="Reset everything"&gt;

&lt;/p&gt;</pre>
<h3>Example 1: Select first level child div and add custom class to it when a button is clicked</h3>
<pre class="lang:xhtml decode:true">	$('#sbt_add1').on("click", function(e){		

		$('.divs_container div:first-child').addClass('purple');

		e.preventDefault();

	});</pre>
<h3>Example 2: Select first level child p tag and add custom class to it when a button is clicked</h3>
<pre class="lang:xhtml decode:true">	$('#sbt_add2').on("click", function(e){			

		$('.divs_container p:first-child').addClass('purple');				

		e.preventDefault();

	});</pre>
<h3>Example 3: Select first level child table cell and add custom class to it when a button is clicked</h3>
<pre class="lang:xhtml decode:true">	$('#sbt_add3').on("click", function(e){		

		$('.divs_container table td:first-child').addClass('purple');

		e.preventDefault();

	});</pre>
<div class="make_demo">

	<form action="https://theextremewebdesigns.com/blog/wp-content/themes/ewd_blog_2017/try_demo.php?post_id=3812" method="post" name="form1" target="_blank" id="form1">


	<input type="hidden" name="shortcode_content" id="shortcode_content" value="" />

        <div class="try_demo_btn_container">


            <button type="submit" name="sbt_make_demo" id="sbt_make_demo" class="btn-primary btn-try-demo">
                Try Demo
            </button>


        </div><!-- .try_demo_btn_container -->

    </form>
    </div>
    
<h5>Simple, isn&#8217;t it?</h5>
<p>Do you know of any other ways to use the <em><strong>:first-child selector in jQuery</strong></em>? Feel free to suggest by commenting below.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://theextremewebdesigns.com/blog/jquery-selector-first-child/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">3812</post-id>	</item>
	</channel>
</rss>
