Accessing ids of external css file in javascript -
i've line of code
this:
htmlcontent = htmlcontent+'<div class="checkbox" id="chkpos[j]">'+optionalpha+'<label class="lclass"><input type="checkbox" class="checkbox" name="answer" value='+optionid+'>'+option+'</label>'+htmloptionimage+'</div>';
and ids
in external css this:
#chkpos1{ /*position: relative;*/ margin-top: 8%; } #chkpos2{ /*position: relative;*/ margin-top: 26%; } #chkpos3{ /*position: relative;*/ margin-top: 17%; }
how can make javascript code ('<div class="checkbox" id="chkpos[j]">'
) access ids?
ideas?
if want use ids in css (though recommend using classes instead cerbrus said) set id this:
htmlcontent = htmlcontent+'<div class="checkbox" id="chkpos' + j + '">'+optionalpha+'<label class="lclass"><input type="checkbox" class="checkbox" name="answer" value='+optionid+'>'+option+'</label>'+htmloptionimage+'</div>';
you can't use [ ]
brackets in css ids css uses these attributes (such input[type=text]
).
like said though, i'd recommend using classes, in js:
htmlcontent = htmlcontent+'<div class="checkbox chkpos chkpos' + j + '">'+ //etc...
css:
.chkpos { /*position: relative;*/ } .chkpos1 { margin-top: 8%; } .chkpos2 { margin-top: 26%; } .chkpos3 { margin-top: 17%; }
Comments
Post a Comment