Utilizzo di JavaScript Sto provando a verificare se nel documento esiste un DIV con ID "test_div".Verificare se esiste un ID DIV con JQuery
sto usando
if (getElementById("test_div"))
nello script di seguito per verificare se il DIV esiste nel documento. Comunque, non funziona. Non ho molta esperienza con Javascript; ma dalla ricerca che ho fatto sembra che il mio problema potrebbe avere qualcosa a che fare con la funzione annidata.
Lo script funziona se mi tolgo la
if (getElementById("test_div"))
Qualcuno sa come controllare se un DIV con il "test_div" id esiste nel documento all'interno della funzione come illustrato di seguito?
<div id="test_div"></div>
<script>
function loadInfo(){
var req = new Request({
method:'get',
url:'getinfo.php,
noCache: true,
onRequest: function(){
if (getElementById("test_div")) {
$('test_div').set('html', 'loading data');
}
},
onComplete:function(responseText, responseHtml){
if (JSON.decode(responseText) != null){
var data = JSON.decode(responseText);
if (getElementById("test_div")) {
$('test_div').set('html', data['test_div']);
}
}
},
onFailure: function(){
if (getElementById("test_div")) {
$('test_div').set('html', '-');
}
}
}).send();
}
window.addEvent('domready', function(){
loadInfo();
});
</script>
Quale framework javascript stai usando? Non sembra jquery o prototipo ... potrebbe avere un modo integrato per farlo. –