alex johnson alex johnson - 2 months ago 29
jQuery Question

Modity HTML within JQuery for checkboxes

I currently have the following function in Jquery which returns the correct set of information:

function checkAllPriceBuilderBoxes() {
var contentzz = $("#props #itemEditor #builderItemsList .listItem .controlCtr").html();

returns the following html:

<input class="control" style="" type="checkbox" _type="checkbox" value="No">

I am looking to modify this html adding the 'checked' text at the end of the html:

<input class="control" style="" type="checkbox" _type="checkbox" value="No" checked>

I have tried the following but does not work.




You need to add attribute to element. use .attr():


If you want the modified string after adding attribute, then you need to to overwrite contenzz string with modified string element.

contentzz = $(contentzz).attr('checked',true)[0].outerHTML;