empty selector in jQuery with example

Empty selector returns all elements that do not have child element nodes.

Example :

    <title>empty Selector</title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"> </script>
    <script type="text/javascript">
    $(":empty").text("This is div.").css({'background-color':'Green','font-size':'20px'});
    <button id="myButton">Click Me</button>
    <button onclick="location.reload()">Reset</button>

Demo :

 In the above example, we have used empty selector. Empty selector returns all elements that do not have child element nodes. In the above example the empty selector selects the empty div and applies CSS and adds content to it.


Post a Comment