Mubeen Hussain Mubeen Hussain - 19 days ago 7
jQuery Question

Unable to get elements/properties from within a class tag using jquery

Im quite a newbie to jquery so if this doesnt make sense much then let me try to explain.

I currently have a section whereby when I click the text, it will create a new row and populate a "default" button. The issue I am having is every time i click it, it populates with a blank element (see 'result im getting') rather then the button itself (see 'what i want it to be').

I have attached my code, would greatly appreciate any help.

var row = $("<DIV></DIV>").addClass("row resource").attr("resource", "new");
var label = $("<SPAN></SPAN>").addClass("label imaged").text("New resource");
label.append($("<SPAN>&nbsp</SPAN>").addClass("defaultJobType").attr("title", "defaultJobType"));


<SPAN class="defaultJobType"><input id = "setDefaultJobType" type="submit" name="Default" value="Set Default"/>&nbsp</SPAN>


Result im getting

<span class="defaultJobType" title="defaultJobType">&nbsp;</span>


what I want it to be

<span class="defaultJobType"><input id="setDefaultJobType" type="submit" name="Default" value="Set Default">&nbsp;</span>

Answer

Do following,

var row = $("<DIV></DIV>").addClass("row resource").attr("resource", "new");

var label = $("<SPAN></SPAN>").addClass("label imaged").text("New resource");
var spanEl = $("<SPAN>&nbsp</SPAN>").addClass("defaultJobType");
spanEl.append($("<input id = 'setDefaultJobType' type='submit' name='Default' value='Set Default'/>"));        

label.append(spanEl);
Comments