I am appending a span with onclick. I cant change this because I am getting an HTML via PHP from another website.
So, I am adding in a table some informations like this:
function getdados(id) {
$('#loader').fadeIn();
$.ajax({
type: "GET",
url: 'index.php',
data: { action: 'getdados', id: id },
success: function(response) {
if(count > 1) {
$('.remove').remove();
console.log(count);
}
response = response.replace(/\+/g, '%20');
var str = response.split("%");
var cval = str[0];
for (var i = 1; i < str.length; i++) {
cval += String.fromCharCode(parseInt(str[i].substring(0,2),16))+str[i].substring(2);
}
jQuery.event.trigger("ajaxStop");
$('.resultados').append(cval);
var titles = $(".title").map(function() { return $(this).text(); }).get(),
dados = $(".dados").map(function() { return $(this).text(); }).get(),
header = $(".headertitle").map(function() { return $(this).text(); }).get();
for(var i = 0; i < dados.length; i++) {
switch(titles[i]) {
case 'Naturesa: ':
titles[i] = 'Natureza: ';
dados[i] = dados[i] + ' - ' + dados[i+1];
dados.splice(i+1, 1);
titles.splice(i+1, 1);
break;
case 'DOC: : ':
titles[i] = 'DOC: ';
break;
case 'Atividade primária: ':
dados[i] = dados[i] + ' - ' + dados[i+1];
dados.splice(i+1, 1);
titles.splice(i+1, 1);
break;
case 'Atividade secundária: ':
dados[i] = dados[i] + ' - ' + dados[i+1];
dados.splice(i+1, 1);
titles.splice(i+1, 1);
break;
}
$('#results-2 table').append('<tr class="remove"><th>'+ titles[i] +'</th><td>'+ dados[i] +'</td></tr>');
}
for(var i = 0; i < header.length; i++) {
var link = $('.headertitle').eq(i).nextUntil('.headertitle').map(function() {
if(this.localName == 'span')
return '<tr class="remove"><td colspan="2">'+this.outerHTML+'</td></tr>';
}).get().join('');
$('#results-2 table').append('<tr class="remove rowTable"><th colspan="2">'+ header[i] +'</th></tr>'+link);
}
$('#loader').fadeOut();
},
error : function(transport) {
jQuery.event.trigger("ajaxStop");
}
});
}
I need to remove all tr class="remove" from the table, but I think it is not possible :(
Someone can help me?
Replace the following code:
$('#results-2 table').append('<tr class="remove rowTable"><th colspan="2">'+ header[i] +'</th></tr>'+link);
With this way, which has a handle to it:
var $tr = $('<tr class="remove rowTable"><th colspan="2">'+ header[i] +'</th></tr>' + link);
$tr.appendTo('#results-2 table');
Keeping the $tr
, you can reuse using:
$tr.remove();
Or, the old school way, you can find the .remove
:
$("tr.remove").remove();
If I don't understand your question, may be you just need to remove the class remove
from the elements, use:
$("tr.remove").removeClass("remove");
使用此行删除带有 class remove 的 tr。
jQuery("tr.remove").remove()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.