JS Add and remove HTML tags

Source: Internet
Author: User

Add a line Price $ (' #add_ladder_price '). Click (function () {    var trhtml = ' <tr align= ' center ' class= ' Tr_ladder_price ' > ' +        ' <td><input style= "Text-align:center" type= "text" name= "purchases" value= ""/></td> "+< c2/> ' <td><input style= "Text-align:center" type= "text" name= "PRICE_CN" value= ""/></td> ' +        ' <td><input style= "Text-align:center" type= "text" name= "Price_us" value= ""/></td> ' +        ' <td ></td> ";    $ (' #tbody_ladder_price '). Append (trhtml);    Alert ("Add Price");})

Delete a row price binds only statically loaded tags the event  dynamic binding needs to be bound with the On () method
$ ('. Cls_delete_ladder_price '). Click (function () {
alert ("Delete price");
$ (this). Parent (). Parent () . Remove ();
//})
Delete a row price   contains dynamically added
$ (document). On ("click", ". Cls_delete_ladder_price", function () {
Alert ("Delete price");
$ (this). Parent (). Parent (). remove ();
});

The On () method is as follows
$ (selector). On (Event,childselector,data,function,map)
The deletion of this tried many times, only the above this easy to use ... Do not know why, I will selector specified as the parent tag to bind the event is not possible, click will not go in.
But I always feel that it is too big to designate selector as document, which is not appropriate. The great God who knows is also looking for the generous enlighten. Thanks a lot.

Give a detailed point of the Jquery.on () method here

JS Add and remove HTML tags

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.