Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
6
rated 0 times [  9] [ 3]  / answers: 1 / hits: 21830  / 10 Years ago, thu, april 3, 2014, 12:00:00

I work with CreateElemant in JavaScript this is my code:



function generateInputs()
{
var i = document.createElement(input);
for(var j=0;j<4;j++)
{
var c = document.createElement(input);
var r = document.createElement(input);
r.setAttribute('type',radio);
document.getElementById('questions').appendChild(r);
c.setAttribute('type',input);
document.getElementById('questions').appendChild(c);
}

i.setAttribute('type',text);

document.getElementById('questions').appendChild(i);

}


And I want to write it with jQuery but I didn't find an equivalent for createElement()


More From » jquery

 Answers
11

Just try with:



function generateInputs()
{
var i = $('<input type=text/>');

for(var j=0;j<4;j++)
{
var c = $('<input type=text/>');
var r = $('<input type=radio/>');

$('#questions').append(c).append(r);
}


$('#questions').append(i);

}

[#71633] Wednesday, April 2, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
marquezb

Total Points: 237
Total Questions: 97
Total Answers: 89

Location: Israel
Member since Wed, Apr 14, 2021
3 Years ago
;