Jquery load select a specific class
Asked Answered
Y

1

9

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?

Yeld answered 3/2, 2013 at 17:49 Comment(0)
F
11

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.

Fixity answered 3/2, 2013 at 17:49 Comment(2)
ok wow that is actually very helpful now, thank you so much. I am assuming you can also grab specific tags within that correct?Yeld
You can go on with any selector.Truffle

© 2022 - 2024 — McMap. All rights reserved.