var selector = '#Id-value_' + index;
var exist = $(selector).exists();
Dostaję błąd dla tego fragmentu kodu.
Mój dokument gotowy funkcja jest
$(document).ready(function() {
});
var selector = '#Id-value_' + index;
var exist = $(selector).exists();
Dostaję błąd dla tego fragmentu kodu.
Mój dokument gotowy funkcja jest
$(document).ready(function() {
});
Nie ma exists()
funkcja w jQuery. Ale można szybko napisać:
//add a new function to jQuery
jQuery.fn.exists = function(){return this.length>0;}
//now let's test it
if ($(selector).exists()) {
// Do something
}
podstawie @ K48 odpowiedź, można również bezpośrednio sprawdzić, czy istnieje ona za pomocą $(selector).length
.
var selector = '#Id-value_' + index;
if ($(selector).length) {
// Do something
}