English 中文(简体)
页: 1 点击首个孩子
原标题:jQuery trigger click on first child

I m trying to invoke a click on first .loader child when document is ready, but no success:

html:

<a class="loader" data-target="david-boy" title="Danny Boy-Rivera">
    <span class="img"><span class="play"></span><img src="img/gallery-image1.jpg" alt="" /></span>
    <h2>Danny Boy</h2>
</a>

j 质量:

//Does not work
$( a.loader:first-child ).bind( click );
$( a.loader:first-child ).trigger( click );
$( a.loader:first-child ).click();
//Works
$( a.loader:first-child ).css("background", "red");

任何想法为什么?

Update

Handler:

$( .loader ).click(function(){
    var name=$(this).data("target");
    callVideo(name);
});

Update2

因此,问题是,我已宣布“<条码>:第一-儿童在手上采取行动。 我改变了他们的地点和一切ok。

最佳回答

您在之前是否界定了手稿?

Here s the EXACT same code from your fiddle except I put the handler BEFORE the trigger

$(document).ready(function(){
    $( .loader ).click(function(){
       alert($(this).data("target")); 
    });
    $( .loader:first-child ).click();
    $( .loader:first-child ).css("background", "red");
});​

这将使你们重新寻求警惕

问题回答

你们需要一名手来参加点击活动......

$( a.loader:first-child ).click(function(){
    alert( clicked );
});

$( a.loader:first-child ).click();

<>Update:

也许,在要素准备好之前,你会随同。

$(function(){
    $( .loader ).click(function(){
        var name=$(this).data("target");
            callVideo(name);
    });
});




相关问题
getGridParam is not a function

The HTML: <a href="javascript:void(0)" id="m1">Get Selected id s</a> The Function: jQuery("#m1").click( function() { var s; s = jQuery("#list4").getGridParam( selarrrow )...

selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

jQuery cycle page with links

I am using the cycle plugin with pager functionality like this : $j( #homebox ) .cycle({ fx: fade , speed: fast , timeout: 9000, pager: #home-thumbs , ...

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

jConfirm with this existing code

I need help to use jConfirm with this existing code (php & Jquery & jAlert). function logout() { if (confirm("Do you really want to logout?")) window.location.href = "logout.php"; } ...

Wrap text after particular symbol with jQuery

What I m trying to do, is wrap text into div inside ll tag. It wouldn t be a problem, but I need to wrap text that appears particularly after "-" (minus) including "minus" itself. This is my html: &...

热门标签