Jquery live () only supports css selectors

Source: Internet
Author: User

After handling the keypress keyboard event yesterday, we need to add the deletion function to the field entries dynamically added to the page today, that is, add a pretty small button behind each field, when you click this button, the corresponding entries are deleted from the database.

To implement this function, you must ensure that any newly added entries can also delete events without refreshing new pages. Therefore, you must use jquery. live () is used to bind the click event to the pretty small button, but because the button is embedded on every entry, they are in a deep level of the DOM tree, I used jquery's children () to select these buttons layer by layer, but I failed to pass the test many times. The error shown on firebug is that the selector cannot be recognized by the jquery kernel, I don't know what's going on at the moment.

When I got back from work in the evening, I went back to my cell phone for a hundred times. Later I learned that jquery's live () only supports CSS selectors. To be honest, I didn't quite understand this sentence at the time, before going to work this morning, I wrote an English article on jquery's blog about the deep mechanisms of live () and die (). Later I understood that I was using live () only selector can be used. jquery's built-in traversal functions, such as children (), parent (), next (), and prev (), are not supported by live, this is also one of the shortcomings of live (). The owner of this blog said that he will study the jquery kernel and fix this defect, but it takes time and there is no way to use it first, currently, this service can meet your needs.

Later, all the traversal functions in the Code were replaced with the css selector, and everything was normal.

Related Article

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.