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

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -