ruby on rails - Array function not working on a JavaScript array created from element text -


so have following element, when clicked on calls javascript function response(tag). pass element "rops" function.

<li><div class="rops"><span class="rops-text"> tag2 </span></div></li> <li><div class="rops"><span class="rops-text"> tag2 </span></div></li> 

so when click on 1 of these elements adds them array. array functions work array, , created array. see following working case , not working case:

they work if create array self:

working case:

var checka = []; checka[0] = "tag1"; checka[1] = "tag2";  alert(checka.indexof("tag2")); //gives me correct answer.  

not-working: array created this:

response(tag) {   myarray[i] = string($(tag).text()); //at current point has ["tag1", "tag2"]   //but if same  alert(myarray.indexof("tag2")); //gives me -1 (similar other array function). 

so in short, creating array using element text cause array functions not work. can please this. not sure why happening? thanks.

try this:

function result(tag){    myarray = document.getelementsbytagname('span');    alert(myarray.item('tag').innerhtml); } 

Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -