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

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -