views:

25

answers:

2

What if I request the URL http://www.google.com via AJAX, for example and in the on successfunction I just wanted to display the I'm feeling lucky button in some div?

For example

$.ajax({
    url: 'www.google.com',
    success: function(html) {
        $('div').html(html);
    }
});

this is for displaying the whole page, but I want only to display the button. How do I do that?

+1  A: 

You could put a div around the button like:

<div id='button'><button>blah</button</div>

and the Ajax URL would be something like:

url: 'www.google.com #button',

Just add the selector to the end of the URL and it will return only that content.

Dave
Amazing? Does this really work? I didn't checked out
Rodrigo Alves
Yes. It's also documented in the jQuery documentation.
Dave
+3  A: 
$.ajax({ 
    url: 'www.google.com', 
    success: function(html) { 
        $('div').html($(html).find('input[name=btnI]')); 
    } 
});

You can replace input[name=btnI] with your own condition.

aRagnis