javascript - Remove HTML Elements from JQuery AJAX load() Response -



javascript - Remove HTML Elements from JQuery AJAX load() Response -

is there possibility remove specific html elements ajax (load) response before placing in container? in case want remove "#containertop", including content, response.

response (html):

<html> <head></head> <body> <div id="containermain"> <div>...</div> <div id="containertop">content-to-remove-including-container-div...</div> </div> </body> </html>

i've tried this, without success.

<div id="middle"></div> <script> $( "#middle" ).load( "http://<url>", function(response, status, xhr){ $response.remove('#containertop'); }); </script>

any ideas?

.load() inserts content straight you. not give chance modify before inserted. such have 2 options:

you can modify content after inserted, before painted in .load() completion handler. you can switch .get() content data, set jquery object, modify using jquery methods, insert modified content page yourself.

here's illustration of sec option:

$.get("http://<url>", function(data) { var temp = $(data); temp.find('#containertop').remove(); $('#middle').empty().append(temp); });

javascript jquery html ajax response

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -