viernes, 9 de octubre de 2009

jQuery doesn´t use dot in the id

I was using jQuery to run animations and setting the html content over a div... for example:

HTML:


Some Content


JAVASCRIPT:

$('#myDiv').hide();
$('#myDiv').html('other content');

It was working ok.

I did a change in the div id, so instead of myDiv, I was using myDiv.ext:

HTML:


Some Content


JAVASCRIPT:

$('#myDiv.ext').hide();
$('#myDiv.ext').html('other content');

This didn't worked using jQuery, but it worked using bare javascript as follows:

document.getElementById('myDiv.ext').style.display = 'none';
document.getElementById('myDiv.ext').innerHTML = 'other content';

So, jQuery doesn't handle ids with dots "." we should try to avoid using dots in the id of an element if we want to use jQuery.

If you keep this in mind I'm sure you'll save some time debugging.

0 comentarios: