javascript - Which is better practice for adding a class using jQuery? -
javascript - Which is better practice for adding a class using jQuery? -
$("#" + parentelementid + " label").attr("class", "disabled")
vs
$('#radiolabel').addclass('disabled'); which pros , cons?
thanks
here advantages of 2 ways this:
addclass("disabled") pros:
addclass() preserve while adding new class. pretty much want preserve ability utilize other classes css styling reasons or mutual selector reasons addclass() makes possible add together disabled class without disturbing other classes on same object other reasons. the code reads little more self-explanatory since name addclass() tells reading code it's doing. addclass() automatically manages separators between class names there no accumulation of separators when have multiple class names can occur if current classname , add together onto string manipulation. attr("class") = "disabled" pros:
addclass() has examine what's there first , add together class pre-existing classes jquery regex match. max speed element.classname = "disabled" (no jquery @ all). javascript jquery html
Comments
Post a Comment