javascript - If 'this' in function is a particular class -
I have a representative who is called when some DOM elements are clicked using their ID or class And I'm inside this 'function', but how can I find out which class or id is it really?
Here's my code:
$ (document) .delegate ("#BLE-Menu Li, #xs-menu, lilist-item", "click" ("(") "; (=" (")"; (= "(") ";" Div> >
this dome object , Which triggers the event so that you can use only DOM methods or jQuery methods to monitor it or its parent: $ (document) .delegate ("# Lg-menu LE, #xs-menu LE, .list-item "," click ", function (e) {var item = $ (this); // see if item matches what item if (item .is ("# Lg-menu li") {// # lg-menu li} else if (item.is ("# xs-menu li") {// should be #xs-menu li} other {// .list-item}} .is () prepares the entire selector assessment for you. You can also inquire the different properties of the element. Such as: item.hasClass (". List item ") // item.list-item classname item.parents (" # LG-Menu "). Length! == 0 // Item # LG-Menu is the original item on page (" #xs-menu "). Length! == 0 // There is a #x in the item- menu parent this tag name ===" light "// This item is a tag
However, if you really should know which item it is, you should probably use different event handlers for each item and try to find out that Once it happens every time.
$ (document) .delegate ("# lg-menu li", "click", function (e) {// code here}) ; $ (Document) .delegate ("# xs- menu", "click", function (e) {// code here}); $ (document) .delegate (".list-object", "click" ", Function (e) {// code here});
Comments
Post a Comment