2

I have a problem about getting title attribute..

$('.copy_button').livequery(function(event){
    $(this).zclip({
        path:'http://togl.me/tema/flash/ZeroClipboard.swf',
        copy: $(this).attr("title")
    });
});

The livequery function is working but I can't get attr('title') to work.

How can I solve this?

Grant Thomas
  • 44,454
  • 10
  • 85
  • 129
oralunal
  • 393
  • 3
  • 16
  • 1
    Are you using any plugins? `livequery` is not a standard jQuery method. – FishBasketGordo Aug 26 '11 at 13:21
  • Yes all of them has a title and I'm using livequery also tried jquery.live.. You can check the problem here http://togl.me.. The problem is really different.. You will understand – oralunal Aug 26 '11 at 13:22
  • Try this: enter http://togl.me. Shorten 1 link. Copy doesn't work... Then refresh the page.. When page loaded I get your last shortened links via Ajax.. But those works fine.. – oralunal Aug 26 '11 at 13:31

2 Answers2

1

Sometimes, the scope of $(this) can change based on where you're at in your method. As you start getting deeper, $(this) can refer to what's currently in scope, instead of what was evented in the first place.

Try doing this and tell me if it works:

$('.copy_button').livequery(function(event){
    var title = $(this).attr('title');
    $(this).zclip({
        path:'http://togl.me/tema/flash/ZeroClipboard.swf',
        copy: title
    });
});
slandau
  • 23,528
  • 42
  • 122
  • 184
0

You can try the following code:

$('.copy_button').livequery(function(event){
    $(this).zclip({
        path:'http://togl.me/tema/flash/ZeroClipboard.swf',
        copy: this.attr("title")
    });
});
Denis Elkhov
  • 166
  • 2
  • 9