Why can't I find my div using a numeric id?
Edit: Sorry, a line got lost.
I'm making a div dynamically, which is
<div id="102">
, with an inner class:
<a class="delete" onClick="del(102)">X</a>
In my javascript file, i'm trying to hide it with
$("#" + id).hide(2000)
But it doesn'开发者_Go百科t appear to be doing anything.
You cannot have a numeric ID. Prepend letter(s) to it, like div102
.
Specs: http://www.w3.org/TR/html4/types.html#type-name.
I'm not sure what the rest of your code is, but this works.
$(document).ready(function(){
$('body').append('<div id="102"><a class="delete" onClick="del(102)">X</a></div>');
});
function del(id){
$("#" + id).hide(2000);
}
http://jsfiddle.net/CcBfs/
this should work.
onClick="$(this).parent().hide(2000);"
$("#" + id).hide(2000)
will hide the element whose id is id
But <a class="delete" onClick="del(102)">X</a>
doesn't have an id
have to say: really bad question
精彩评论