Search code examples
javascriptjqueryhtmljquery-load

Jquery load select a specific class


So I am using Jquery's load function like so,

$('#id').load("http://www.thisiswhyimbroke.com");

I know you can add id selectors after the url, but the content im looking for is not contained within an id, is there a way I can select a particular class name?

Even further, if I could select the first li item, then select the class with name item within it, is that possible?


Solution

  • You can provide any selector, for example

    $('#id').load("http://www.thisiswhyimbroke.com li:first .someclass");
    

    From the documentation :

    Loading Page Fragments

    The .load() method, unlike $.get(), allows us to specify a portion of the remote document to be inserted. This is achieved with a special syntax for the url parameter. If one or more space characters are included in the string, the portion of the string following the first space is assumed to be a jQuery selector that determines the content to be loaded.