I am trying to use a delegate to call a function when I click on a specific set of links. I already used it on another page. He worked there. But this time I could not even find where the problem is.
My links were dynamically generated, they look like
<a class="thumbLink" href="#" id="My HomeTown-1"><small>My HomeTown</small></a>
And the jQuery delegate function,
$(document).ready(function(){
$("#albumHolder").delegate('a.thumbLink', 'click', this.loadAlbum);
this.loadAlbum = function(){
var id = this.id;
var number = id.lastIndexOf("-");
var alubmName = id.subString(0, number);
alert(albumName);
}
});
Update:
I tried both versions, but I can't get it to work!
$("#albumHolder").delegate('a.thumbLink', 'click', function loadAlbum(){
var id = this.id;
var number = id.lastIndexOf("-");
var alubmName = id.subString(0, number);
alert(albumName);
});
this.loadAlbum(){
var id = this.id;
var number = id.lastIndexOf("-");
var alubmName = id.subString(0, number);
alert(albumName);
}
$("#albumHolder").delegate('a.thumbLink', 'click', this.loadAlbum);
The above code is in $(document).ready(function(){});. It's right?? I also tried putting them in a separate file js. I can not make it work.
Any idea about my problem !!!
user405398
source
share