Reputation: 1289
I created a input element with jQuery like that:
var element = $('<input />', {
name: name1,
id: id1,
type: 'text'
});
And I want to return the DOM element associated with it. However, element is not a DOM (yet). How can I transform it to DOM element?
Upvotes: 4
Views: 399
Reputation: 47776
jQuery returns an array-like object of DOM elements. Using the array indexer will always allow you to get a specific element, like so:
var domElement = element[0];
Alternatively, jQuery provides a function just for that, .get
:
var domElement = element.get(0);
Upvotes: 4
Reputation: 263
you can check this solutions to use maybe a DOM parser. Converting HTML string into DOM elements?
or just use some native javascript functions. Creating a new DOM element from an HTML string using built-in DOM methods or prototype
Upvotes: 1