Panagiotis Koursaris Panagiotis Koursaris - 1 month ago 6
HTML Question

Remove specific attribute after having get from .html() jquery method

I have a search engine for users that works with jquery ajax. The problem is that I want to get a whole of html page except the search inputs.

Take a look to my code:.

<script>
$(document).on('change', '.auto-select', function(e){

e.preventDefault();

var tags = $('#auto-tag-script').serialize();
var contracts = $('#auto-contract-script').serialize();
var educations = $('#auto-education-script').serialize();
var towns = $('#auto-town-script').serialize();

runAjax(tags, contracts, educations, towns);

});

function runAjax(tags, contracts, educations, towns) {
$.ajax({
url: 'http://localhost/jobs/public/anazitisi-ergasias?' + tags + '&' + contracts + '&' + educations + '&' + towns
}).done(function(data){

$('div.show-html-from-ajax').html(data);

});

}

</script>


With the above code the search form appears again in my page.

Is there any way to escape this form.

Answer

You can hide it 2 ways...before you insert it (best way) or after you insert it

    $.ajax({
        url: '...'
    }).done(function(data){
        // create jQuery object from response
        var $html = $(data);
        //hide within that object
        $html.find('.search-form-for-hide').hide();
        // insert the object
        $('div.show-html-from-ajax').html($html);
         /*******   OR ***************/
        //  the html is in the DOM now, can do whatever might be needed to it
        $('.search-form-for-hide').hide();

    });

For many plugins you would need to insert first and then call the plugin