Boolean HTML Attributes

(Because of some framework code I use, not calling setAttribute(), or calling removeAttribute() is difficult.) Then I would submit that the framework code needs fixing, or dumping. You can’t setAttribute to unset an attribute, by design. Any solution you found involving out-of-band values like ‘null’, if it happened to work in any particular browser, would … Read more

decodeURIComponent vs unescape, what is wrong with unescape?

What I want to know is what is wrong with escape/unescape ? They’re not “wrong” as such, they’re just their own special string format which looks a bit like URI-parameter-encoding but actually isn’t. In particular: ‘+’ means plus, not space there is a special “%uNNNN” format for encoding Unicode UTF-16 code points, instead of encoding … Read more

Is there a best practice for generating html with javascript

Options #1 and #2 are going to be your most immediate straight forward options, however, for both options, you’re going to feel the performance and maintenance impact by either building strings or creating DOM objects. Templating isn’t all that immature, and you’re seeing it popup in most of the major Javascript frameworks. Here’s an example … Read more

jQuery get the id/value of element after click function

$(“#myid li”).click(function() { alert(this.id); // id of clicked li by directly accessing DOMElement property alert($(this).attr(‘id’)); // jQuery’s .attr() method, same but more verbose alert($(this).html()); // gets innerHTML of clicked li alert($(this).text()); // gets text contents of clicked li }); If you are talking about replacing the ID with something: $(“#myid li”).click(function() { this.id = ‘newId’; … Read more