javascript - How to handle spaces in div id in jquery -
i getting id of div external source , in spaces coming in id , how value of id. here div example:
<div id="123456abc" class="classname" onclick="javascript:addvalue(aa.value,'33',bb.value,'1000')"></div> <div id="78904 bbc" class="classname1" onclick="javascript:addvalue(aa.value,'55',bb.value,'2000')"></div>
i need class name id. here doing:
function addvalue(aa, bb) { var classofdiv = $('#123456abc').attr('class'); var classofdivs = $('#8904 bbc').attr('class'); alert(classofdiv); alert(classofdivs); }
the first alert working fine second not fetching value. how can handle this? values dynamic.
use $("div[id='78904 bbc']")
access element has spaces in id, try:
var classofdiv = $("div[id='123456abc']").attr('class'); var classofdivs = $("div[id='78904 bbc']").attr('class'); alert(classofdiv); alert(classofdivs);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> <div id="123456abc" class="classname" onclick="javascript:addvalue(aa.value,'33',bb.value,'1000')"></div> <div id="78904 bbc" class="classname1" onclick="javascript:addvalue(aa.value,'55',bb.value,'2000')"></div>
Comments
Post a Comment