简体   繁体   English

关于javascript的功能无法在div悬停时触发的问题

[英]Issue regarding javascript function not firing on hover of div

I have a use case whereby i know that all the divs i am interested in will have the word 'tabz' in them but have yet to find a way to fire my jquery when a user clicks on a div with such an id. 我有一个用例,据此我知道我感兴趣的所有div中都会有单词“ tabz”,但是当用户单击具有此类ID的div时,还没有找到触发我的jquery的方法。

$('div[id=*"tabz"]').on("click", function()
{
 alert(event.target.id);
});

This is what i have however the alert never fires. 这就是我所拥有的,但是警报永远不会触发。

When I replace the method with : 当我将方法替换为:

   $('div').on("click", function()
  {
    alert(event.target.id);
  });

it will give me the following: 它会给我以下内容:

tabz91 tabz91

So i know there are divs that meet my selector but it I am unsure as to why the alert is not firing. 因此,我知道有些div符合我的选择器,但是我不确定为什么不触发警报。

Any help greatly appreciated 任何帮助,不胜感激

$('div[id*="tabz"]').on("click", function()
{
 alert(event.target.id);
});

It's a typo, * and = inverted. 这是一个错字, *=颠倒了。 See this example : http://jsfiddle.net/Xcn6N/ 参见以下示例: http : //jsfiddle.net/Xcn6N/

try instead of =* it is *= 试试而不是=*它是*=

$('div[id*="tabz"]').on("click", function() {
 alert(event.target.id);
});

For Further Assistance on Selectors in jQuery see this page 有关jQuery中选择器的进一步帮助,请参见此页

jQuery Selectors jQuery选择器

The correct syntax is simply 正确的语法很简单

$('div[id*="tabz"]') $('div [id * =“ tabz”]')

(the = and the * are inverted in your example). (在示例中,=和*颠倒了)。

You may use 您可以使用

$('div[id$="tabz"]') $('div [id $ =“ tabz”]')

if the id attribute ends with your pattern. 如果id属性以您的模式结尾。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM