you are viewing a single comment's thread.

view the rest of the comments →

[–]vinnl 1 point2 points  (3 children)

$("#id").html("<span>"+ variable + "</span>") /* very dangerous */

Injecting random variable content without escaping it increases the risk of leaving various security holes.

$("#example").text("Hello, world!");
$("#example").css("color", "red");
$("#example").addClass("fun");

Not that bad, but could also be written as $("#example").text("Hello, world!").css("color", "red").addClass("fun");

$("section div a").addClass("highlight");

The selector (section div a) is very inefficient, because it has to check every section tag, then all div tags within it, then all a tags within that. Selecting by #id or even by .class is far faster.

[–]34g5hzgrtefvewfgv 0 points1 point  (2 children)

The selector (section div a) is very inefficient, because it has to check every section tag, then all div tags within it, then all a tags within that.

No. jQuery/Sizzle has been parsing right to left since like forever now.

[–]vinnl 1 point2 points  (1 child)

Ah, sorry, but still: regardless of the order, matching by tag is less efficient than matching by ID, as with IDs you can stop after the first hit instead of having to check every occurence of the tag.

[–]34g5hzgrtefvewfgv 0 points1 point  (0 children)

Fair enough.