javascript - What's the recommended way to create an HTML element and bind a listener to it using jQuery? -


At this time I get it using something like this:

  var MyElem = "& lt; tr id = 'tr-1' & gt; & lt; td & gt; Content & lt; / td & gt; & lt; / tr & gt;"; $ ("# Mytable") enclosed (myElem). $ ("#Tr-1"). Click (function () {// blah blah}); Traditionally, when I was not using jQuery, I did something like this:  
  var myElem = document.createElement (. ..); Var myTable = document.getElementById ("myTable"); MyTable.appendChild (myElem); Mary Elm Click on = function () {// blah blah}  

In the second approach, I already have a reference to myElem and I do not want to don ( $ ("# tr-1") ), such as the jQuery approach, and so it should be especially fast in larger pages. Is not there a better jQuery-ish method to accomplish this task?

You delete it below /

  $ ("& lt; Tr id = 'tr-1' & gt; & lt; td & gt; Content & lt; / td & gt; & lt; / tr & gt; "(function () {// blah blah}) . Append-to ("# myTable");  

This takes the need to find the element, and unless you actually call it, you are working with a document section, which makes it faster for the DOM operation it happens.

There is a version 1.4 which does not work for enough for your example, but in some cases it is even more compact that you may want to check.


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -