alex johnson alex johnson - 1 year ago 91
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.



Answer Source

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;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download