Hi, I was just wondering if there was a createElement equivalent in jQuery. e.g. var el = document.createElement('div');
I know I can create it with the inbuilt innerHTML way in jQuery - $('<div id="foo" />'); But I like to add event handlers to the element I've just created without having to traverse the dom to find it and then assign an event listener. e.g. This is how I like to do it: var altPlayerControlsA3 = document.createElement('a'); altPlayerControlsA3.href='#'; altPlayerControlsA3.setAttribute('style','margin:5px;'); altPlayerControlsA3.id="myytplayerControlsMute"; altPlayerControlsA3.textContent="Mute"; altPlayerControlsA3.addEventListener('click', function(e){ e.preventDefault(); //do stuff }, false); document.body.appendChild(altPlayerControlsA3); but with jQuery I seem to have to do it like this: $('body').append("<a href="#" id="myytplayerControlsMute"' style="margin:5px;">Mute"); $('#myytplayerControlsMute').click(function(){... Is jQuery able to create elements not using innerHTML? -- View this message in context: http://www.nabble.com/Is-there-a-createElement-equivalent-in-jQuery--tp20827512s27240p20827512.html Sent from the jQuery General Discussion mailing list archive at Nabble.com.