Significance of >* in the url parameter of jQuery .load()

Viewed 22

I am trying to reload an element via jQuery and curious to know what is the difference between this

$("#elementID").load(location.href+" #elementID >*");

and this

$("#elementID").load(location.href+" #elementID");
1 Answers

> is the direct child selector and * means "any element". So #elementID > *" means "all direct child elements of #elementID".

Basically, the > * prevents you from having multiple #elementID elements.


When you load using:

$("#elementID").load(location.href+" #elementID");

Then what you'll get is:

<div id="elementID">
    <div id="elementID">
        <p>Some Text<p>
        <span>More Text</span>
    </div>
</div>

So, we tell jQuery to grab all child elements and load those into the page:

$("#elementID").load(location.href+" #elementID > *");

Then what you'll get is:

<div id="elementID">
    <p>Some Text<p>
    <span>More Text</span>
</div>
Related