На странице есть несколько тегов с одинаковым id (так получилось). Как при помощи jQuery удалить последний тег?
$('div#block').last().remove();
$("button").click(function () {
$("[id='smth']").last().remove()
})
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<button>Remove</button>
<div id="smth">First</div>
<div id="smth">Second</div>
<div id="smth">Third</div>
<div id="smth">Last</div>
<div id="other">With other id</div>
Можно просто перебрать элементы, и если элемент последний грохнуть:
<div id="test">1</div>
<div id="test">2</div>
<div id="test">3</div>
<script>
var el_count=$('[id=test]').length;
if(el_count>1)
var el_index=0;
$('[id=test]').each(function(){
el_index++;
if(el_index==el_count){
$(this).remove();
}
});
}
</script>
Сборка персонального компьютера от Artline: умный выбор для современных пользователей