I have a set of checkboxes with span elements as their titles. I want the text in the span to wrap with a url once the checkbox is checked. However, I do have the code down for selecting the span class names. In order for my code to work I have my checkbox id the same name as my span. This does work if I set the array myself but for some reason I cannot get my array to work when it is created with the script. Here's the code
HTML:
<div id="product_list" style="float:left; clear:right;">
<input type="checkbox" id="p01" name="system[]" value="p01" form="compare">
<span style="margin-left:20px;" class="p01">product one</span>
<br/>
<input type="checkbox" id="p02" name="system[]" value="p02" form="compare">
<span style="margin-left:20px;" class="p02">product two</span>
<br/>
<input type="checkbox" id="p04" name="system[]" value="p04" form="compare">
<span style="margin-left:20px;" class="p04">product three</span>
<br/>
<input type="checkbox" id="p05" name="system[]" value="p05" form="compare">
<span style="margin-left:20px;" class="p02">product four</span>
<br/>
</div>
JQUERY:
var arr = [];
arr = $('#product_list span').not('.hidden').map(function(i,e) {
return $(e).attr('class');
}).get().join(', ');
alert(arr);
//arr = ["p01", "p02", "p03", "p04"]; works but not the above.
jQuery.each(arr , function(index, value){
$("#"+ value).click(function(){
// alert("clicked");
if ($(this).attr("checked") == "checked"){
$('.'+value).wrap('<a href="#" id="comparelink" target="_blank"></a>'); $('a').link('href', '#');
}
else {
$('.'+value).unwrap('a');
}
});
});
example