Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery traverse html result of $.get(url, function(data){

Tags:

jquery

I'm wondering what the correct syntax is to traverse the data returned of this function:

$.get(url, function(data){
            alert(data);
        });

data.find("table") or similar does not work. The returned html data looks like this, parsed from a django template:

<div class="pagination"> 
        <span class="step-links"> 

            <span style="visibility:hidden;">previous</span> 
            <span class="current"> 
                    Page 1 of 2.
            </span> 
            <a id="next" href="?page=2">next</a>  
        </span> 
    </div> 

        <form class="" id="action-selecter" action="" method="POST"> 
        <div class="action_dropdown"> 
            <label>Action: <select name="action"> 
                <option value="" selected="selected">---------</option> 
                <option value="new_selection">Add to new selection</option> 
                <option value="delete_selected">Delete selected projects</option> 
            </select></label> 
            <button type="submit" class="button" title="Run the selected action" name="index" value="1">Go</button> 
        </div> 

        <div id="ajax_table_result"> 
            <table cellspacing="5"> 
                ...
                </thead> 
                    <tbody> 
                     ...

                    </tbody> 
            </table> 
        </div> 
    </form> 
like image 307
Thomas Kremmel Avatar asked Dec 30 '22 06:12

Thomas Kremmel


1 Answers

Remember to wrap your results in the jQuery wrapper to use jQuery methods against it.

$.get("script.php", {foo:"bar"}, function(results){
  var table = $("table", results);
  /* from comments: how to get span.step-links */
  var spans = $("span.step-links", results);
}, "html");
like image 104
Sampson Avatar answered Feb 15 '23 09:02

Sampson