简体   繁体   中英

How do I target this <a> in jQuery

Heres my jQuery

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.23/jquery-ui.min.js"></script>
<script>
$('div.description a').focus(function(e){
    alert('asas');
});

Im trying to snag this little guy.

<body style="margin:0; text-align:center">

<div id="container">

    <div id="contentArea">
        <div class="cell">
            <a href="#"><img  class="gray" src="../images/kci.png" /></a>
        </div>
        <div class="cell">
            <a href="#"><img class="gray" src="../images/ksw.png" /></a>
        </div>
        <div class="cell">
            <a href="#"><img class="gray" src="../images/amc.png" /></a>
        </div>
        <div class="cell">
            <a href="#"><img class="gray" src="../images/cab.png" /></a>
        </div>


        <div class="description">
            <a href="">flyKCI.com</a>
        </div>

    THISS GUYY ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

        <div class="description">
            <a href="">Kansas Speedway</a>
        </div>
    </div>

</div>

I want to target all a tags with the class description and then shoot out that alert when it is hovered over.. or is it focused on? either or. whatever.

it is hovered over.. or is it focused on?

on mouseover :

$('div.description a').on('mouseover', function(){
    alert('asas');
});

EDIT:

It is not working because you have to load it on document ready or after the markup.

$(function(){
 //your script
})
$("div.description a").mouseover(function() { alert('asas'); });

将在鼠标悬停时发出警报。

Here is an example of how to use the hover method:

$("td").hover(
  function () {
    $(this).addClass("hover");
  },
  function () {
    $(this).removeClass("hover");
  }
);

where the first function is your handler for the mouseenter event, and the second call is for the mouse leave event.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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