jquery div id is not taking on dynamic div id creation
I am creating a set of dynamic divs
Let div id is div1开发者_StackOverflow中文版 div2 div3 etc
in my function for getting div id am concatinating
var divid= 'div'+1
var divid= 'div'+2
etc.
if i call jquery slide down
$('#div1').slideDown('slow');
Its working ,but if i use
$('#divid').slideDown('slow');
Its not working . Why? divid is having same value.. What i am missing??
In the example you show:
$('#divid')
divid
is interpreted as a literal string, not a variable.
What you are probably looking for is
$('#'+divid)
Change
$('#divid').slideDown('slow');
to
$('#'+divid).slideDown('slow');
String literal v.s variable issue
jQuery is looking for a div with the id 'divid', that's what $('#divid')
does. What you want is to use the variable divid to search, you need to do $('#'+divid)
.
divid
is string not variable in your case.
$("#"+divid).slideDown("slow");
var divid= 'div'+1
var divid2= 'div'+2
jQuery('#'+divid).slideDown('slow');
you have to pass proper selector to jquery
精彩评论