2011-11-10 12 views
-2

I'm trying to bind some specific functions to specific links that have class "aMySpecialClass". Example:入手方法<a href> elements with specific class?

<a href="#" class="aMySpecialClass"></a> 

I tried several variations of the following code, no go...

jQuery('a').find('.aMySpecialClass').live(
    'click', 
    function(event) { 
     jQuery.fn.myfunction(this); 
    }); 

Can jQuery find all the using jQuery('a')?

edit: Noted that those links and classes aren't defined at run time, they are dynamically generated after the page is ready, it sends a query to the server, and with the results, it build those links with specific class afterwards.

+2

jQueryのドキュメント – bravedick

答えて

3

I hate to say it, but read the docs.基本的にはちょうどCSS selector syntaxです。

jQuery('a.aMySpecialClass').on('click', function (event) 
{ 
    jQuery.fn.myfunction(this); 
}); 
3

jQuery('a.aMySpecialClass')を試しましたか?

+0

ガッチャを読んでください!これは私がライブでそれを後で組み合わせなければならなかったということでした。ありがとう! – codenamezero

2

findを使用すると、の中にというリンクがあります。ただ、タグとクラスの両方のためのセレクターを作る:

jQuery('a.aMySpecialClass') 
3

はこれを試してみてください:

$('a.aMySpecialClass').live(
    'click', 
    function(event) { 
     jQuery.fn.myfunction(this); 
}); 
+1

'.live()'はjQuery 1.7では非推奨です。代わりに '.on()'を使うべきです。 http://api.jquery.com/live/ –

+0

これは私がやったことです、あなたに感謝Smamatti。私はそれらを動的に生成した後、この関数をトリガすることができました。 – codenamezero

+0

@MattBallそうです。まだ古いバージョンを使用して、それを考えなかった。 – Smamatti