How to load up CSS files using Javascript?

Here’s the “old school” way of doing it, which hopefully works across all browsers. In theory, you would use setAttribute unfortunately IE6 doesn’t support it consistently. var cssId = ‘myCss’; // you could encode the css path itself to generate id.. if (!document.getElementById(cssId)) { var head = document.getElementsByTagName(‘head’)[0]; var link = document.createElement(‘link’); link.id = cssId; … Read more

How do I attach events to dynamic HTML elements with jQuery? [duplicate]

I am adding a new answer to reflect changes in later jQuery releases. The .live() method is deprecated as of jQuery 1.7. From http://api.jquery.com/live/ As of jQuery 1.7, the .live() method is deprecated. Use .on() to attach event handlers. Users of older versions of jQuery should use .delegate() in preference to .live(). For jQuery 1.7+ … Read more