最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Jquery: exclude element - Stack Overflow

programmeradmin1浏览0评论

I have a following code:

$(document).ready(function()
{
   $('a[rel]').each(function()
   {
      $(this).qtip(
      {
         content: {
            text: '<img class="middle" src="i/icon_processing.gif" alt="l">Loading...',
            ajax: {
               url: $(this).attr('rel')
            },
            title: {
               text: $(this).text(),
               button: true
            }
         }
    })
      .click(function() { return false; });
   });
});

This code make all rel's on pages to work with tipsy jquery plugin. The problem is that i have a specific div with some id, that holds content with rel that needs to be excluded from this function.

I have a following code:

$(document).ready(function()
{
   $('a[rel]').each(function()
   {
      $(this).qtip(
      {
         content: {
            text: '<img class="middle" src="i/icon_processing.gif" alt="l">Loading...',
            ajax: {
               url: $(this).attr('rel')
            },
            title: {
               text: $(this).text(),
               button: true
            }
         }
    })
      .click(function() { return false; });
   });
});

This code make all rel's on pages to work with tipsy jquery plugin. The problem is that i have a specific div with some id, that holds content with rel that needs to be excluded from this function.

Share Improve this question edited Jun 6, 2011 at 11:14 Reporter 3,9485 gold badges35 silver badges49 bronze badges asked Jun 6, 2011 at 11:11 Milen MihalevMilen Mihalev 3501 gold badge7 silver badges22 bronze badges
Add a comment  | 

3 Answers 3

Reset to default 10

You could use not() to exclude elements:

$('a[rel]').not('#IdOfElement').each(function()

You can use :not() in your selector.

For example: $("a[rel]:not(div#divId a[rel])")

A jsfiddle illustrating the use of the :not selector in your case: http://jsfiddle.net/6s6Mm/

You can exclude specific Elements with the .not() function like this:

$('a[rel]').not('#sepcialElement').each(...);
发布评论

评论列表(0)

  1. 暂无评论