3 ms·
Further more, what's wrong with chaining function calls? It makes the whole thing a lot easier to read. $("<p>") .addClass("greeting") .htm
by jamesrom 14y ago
Further more, what's wrong with chaining function calls? It makes the whole thing a lot easier to read.
$("<p>")
.addClass("greeting")
.html("Hello World")
.appendTo("#helloWorld .output")
And your second example:
$("<p>")
.addClass("greeting")
.append(
$("<span>")
.html("Hello ")
.append(
$("<a>")
.prop("href", "google.com")
.html("World")
)
)
.appendTo("body");
It's just as verbose but much more readable.
- chime 14y agoSpeed might be a godo reason for the more compact version, especially if you're doing this in a loop.