Using attribute selector with .load() or variable
Hi everybody,
I try to load specific text from a page into a string. When I'm on the specific page I can do this as follows:
- var wantedText = $("td > span[style='color: #00AA00; font-weight: bold;']").text();
But I want to get this text from another webpage using AJAX, I tried using .load() as follows:
- $('#somediv').load(Url+" td > span"); //this loads 3 spans into #somediv (including the one I need)
- $('#somediv').load(Url+" td > span[style='color: #00AA00; font-weight: bold;']"); //this does nothing
I also tried loading the entire page into a string using .ajax() like this:
- $.ajax({url: Url, dataType: "html", cache: false, success: function(responseText){
- //entire webpage is in the string responseText
- }
- });
I tried the following things to get the text I want from that string (responseText):
- alert(responseText); //returns the entire page markup in an alertbox
- alert( $("td > span[style='color: #00AA00; font-weight: bold;']", responseText ) ); //returns [object Object]
- alert( $("td > span[style='color: #00AA00; font-weight: bold;']", responseText ).text() ); //returns nothing (empty alertbox)
- alert( $("td > span[style='color: #00AA00; font-weight: bold;']", responseText ).html() ); //returns null
I've tried a lot more, mostly variants of what I showed in this post, most of them I have already forgotten however.
Nothing so far works, how do I get the text from a span that can only be recognized by it's attributes using AJAX?