开发者

using jquery to get dom elements name

开发者 https://www.devze.com 2023-04-13 07:35 出处:网络
Is there a way to retrieve a elements name as a string that is also cross browser compatible. for example I have an event that I look at the target and I want to just get the name of it. So for examp

Is there a way to retrieve a elements name as a string that is also cross browser compatible.

for example I have an event that I look at the target and I want to just get the name of it. So for example I click on a a tag and the eventListener returns the event.

myEventListener: function(event){
  strName = event.target
}

The above gives me the target but what I want is just a value of the name of the a tag. so an a tag would give me a string result of "a" so something like this pseudo code.

 myEvent开发者_C百科Listener: function(event){
  strName = event.target.name
}


Your pseudocode should work just fine! A name property is exposed on a elements.


You can get the name by using

$(event.target).attr("name")

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号