I came across the following jquery
syntax
var some_variable = $("<input>").attr("type", "some type").attr("name", "some name").val(JSON.stringify(someobj));
I want to know what the $("<input>")
syntax is doing? what is the meaning of <
, >
sign in here?
The syntax in the jQuery object of your example is used to create a new element, in this case an input
. Also note that you can set the properties in a single jQuery object instead of chaining multiple attr()
calls:
$("<input>", {
type: 'text',
name: 'name',
value: JSON.stringify({ abc: 123 })
});