开发者

What does "a." mean in this snippet of Javascript?

In the Javascript below, what does the a. before the cell1 signify?

<script type='text/javascript'>
$(function(){
    $("a.cell1").click(function(){

EDIT: Thanks for the answers. Would it work if I did this to the Facebook Like button:

<fb:like href=""  clas开发者_Python百科s="cell1" send="true" layout="button_count" width="450" show_faces="false" font="arial"></fb:like>


It means an A tag with a cell1 class:

 <A href="..." class="cell1">text</a>

will be matched


$('a.cell1') is a jQuery selector; it acts the same way that css selectors do. a. doesn't mean anything in JavaScript. In this context, though, it's getting a <a> with the class cell1.


The script you showed uses a third-party javascript library called jQuery. The syntax: $('blah') is used to pick out all DOM elements matching the CSS selector blah. In this case, the code is selecting all elements like <a class="cell1".../>


As others have mentioned, it selects a elements with a class of cell1.

To your added question about Facebook, you might need to use jQuery's .live() to bind the click event to it, since Facebook adds the a element after page load.

If .click() doesn't work, try .live().

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜