I have a created a sortable with jQueryUI and after sorting I want to replace all integers in this code block with an other integer, except the integers in textarea, input and other form values. 开发者_如何学编程This is what I have:
$('.sortable').sortable({
stop: function(event, ui) {
ui.item.parent().find('li').each(function(index) {
var new_html = $(this).html().replace(/\d+/g, (index + 1)).replace(/\d+/, (index + 2));
$(this).html(new_html);
});
}
});
Help is greatly appreciated. Best regards, .wired
Sounds like a job for .not()
var tagsToReplace = $(this).children().not("input, textarea");
tagsToReplace.each(function(index) {
$(this).html() = $(this).html().replace(/\d+/g, (index + 1)).replace(/\d+/, (index + 2));
}
精彩评论