开发者

Passing arguments to Jquery

I have a list item

<ul><li id='1'>Testing</li></ul>

I want to pass the id of this element (1) to a jquery snippet. For example:

$('#homepage li').qtip({
  content: {
  url: 'testsite.php?id=!!!THIS IS WHERE THE ID SHOULD BE PASSED!!!',
  method: 'get'
  },
  show: 'mouseover',
  hide: 'mouseout',
  })

Any 开发者_运维知识库ideas?


You need to use a .each() here so you can reference the element as you're setting it up, like this:

$('#homepage li').each(function() {
  $(this).qtip({
    content: {
      url: 'testsite.php?id=' + this.id,
      method: 'get'
    },
    show: 'mouseover',
    hide: 'mouseout'
  });
});

Note that your numeric only IDs are only valid in HTML4 (though they're just fine in HTML5).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜