javascript - Editing results while being appended? -


i have following script displays data returned serverside page onto clientside page:

function getresults() {     var search;      search = $(".txtsearch").val();       $.ajax({         url: 'search.aspx',         type: 'post',         data: { strphrase:search },         error: function(xhr, status, error)         success: function(results)          {              $("#resultscontainer").empty();              $("#resultscontainer").append(results);          }     }); } 

is possible check results returned being appended , make changes it?

for example, imagine results returned html follows:

<div><a href="link1.xls">link 1</a></div> <div><a href="link2.xls">link 2</a></div> <div><a href="link3.doc">link 3</a></div> <div><a href="link4.xls">link 4</a></div> 

is possible check .doc in links , remove full div around particular link leaving following?

<div><a href="link1.xls">link 1</a></div> <div><a href="link2.xls">link 2</a></div> <div><a href="link4.xls">link 4</a></div> 

yes, try this:

success: function(results)      {          var $results = $(results);         $results.find('a[href$=doc]').parent().remove();         $("#resultscontainer").empty().append($results);      } 

this places results in jquery object, turning string dom elements.

then uses jquery's .find() method locate nested <a> elements href attribute ends with doc.

it traverses .parent() element, , calls .remove().

notice the .append() method appends $results modified. not original results string.


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -