0

I have a site called site.com and I want to check if the classname is present on my other page http://site.com/subfolder and if it is yes then perform the code.

$(document).ready(function() { 
    if ($('http://site.com/subfolder classname').length > 0) {
        $('.headline').after('<div>text</div>');
    }
});

Any help is greatly appreciated.

2 Answers2

2

You can use a selector with a URL in it such as :

$('a[href="url"].classname')

but not in the way you are using it

King Friday
  • 25,132
  • 12
  • 90
  • 84
0

You can select an element from another page with the .load() method.

Example:

$("#myElement").load("http://http://stackoverflow.com/questions/13588441/is-it-possible-to-use-url-as-selector #question");

This will load the div with the id question from this page in the element with the id myElement (if there were no cross domain policy).

For more information see the docs.

11684
  • 7,356
  • 12
  • 48
  • 71