Jquery html() not not working-Collection of common programming errors
I have a simple js function:
function changeContent(id, content) {
$(id).html(content);
}
which gets called on ajax callback. id is an id of a div, and $(id) does indeed find it.
On Chrome I get an unhandled exception that HTMLDivElement doesn’t contain method html(), while on IE8 and FF simply nothing happens, although when viewing in degub, .html() does appear in the dynamic method list.
What am I doing wrong?
EDIT: No, I’m not passing the id with #. I’ve tried that, it returned null, now it actually returns something. Is there another problem??
EDIT again: seems I was doing something else wrong. I’ve put the # back, now it works.
-
Try use jQuery(id) instead.
You are sure you don´t pass the id without “#” right?
-
Are you passing simply the ID as a string? In which case I would think it’s not truly being found, maybe try this?
function changeContent(id, content) { $('#'+id).html(content); }
Originally posted 2013-11-29 06:07:16.