I need to fetch all span values in a div into array or string
var tag_text_arr=$("#div_id span").each(function(){
return $(this).text();
});
Actually i need to fetch all span values inside div and want to create a string like this
span1_val|span2_val|span3_val|span4_val
If this is possible explain me…
This should output your required string:
Working demo: http://jsfiddle.net/HmUUB/
This will start the numbering at
span0, notspan1. If you want it to start atspan1, use+(index + 1)+instead of+index+. (example)If I read your question wrong (and you don’t want
spann_prefixed to each element in the string, you can just use jQuery’s$.map()function:Working demo: http://jsfiddle.net/BQLj6/