tags:

views:

91

answers:

1

I'm trying to execute two events using the same class in jquery... having one heck of a time getting this working?

I need the id from the class so I can't use that instead... theres gotta be a way to do this!

$(document).ready(function() {
$("a.comm_link").anchorAnimate()
});

function open_Comm(id) {
$('.comm_link').live("click",function() {
var id = $(this).attr("id");
$("a.commscroll"+id).anchorAnimate();
$("#comment_div"+id).css('display','');
$("#commval"+id+":input:visible:enabled:first").focus();
$("#commval"+id).val("");
$("textarea#commval"+id).blur(function() {
if($("#commval"+id).val() == "") {
$("#comment_div"+id).css('display','none');
}
});
return false;
});
}

/*******
*** Anchor Slider by Cedric Dugas   ***
*** Http://www.position-absolute.com ***
Never have an anchor jumping your content, slide it.
Don't forget to put an id to your anchor !
You can use and modify this script for any project you want, but please leave this comment as credit.
*****/
jQuery.fn.anchorAnimate = function(settings) {
settings = jQuery.extend({
speed : 1200
}, settings);   
return this.each(function(){
var caller = this
$(caller).click(function (event) {  
event.preventDefault()
var locationHref = window.location.href
var elementClick = $(caller).attr("href")
var destination = $(elementClick).offset().top;
$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination}, settings.speed, function() {
window.location.hash = elementClick
});
return false;
})
})
}

Heres the html:

<div class='comment' id='comment".$eid."' style='float:right;padding-right:3px;visibility:hidden;'>
<a href='#commscroll".$eid."' onclick=\"javascript:open_Comm('".$eid."');\" class='comm_link' id='".$eid."'>
<img src='http://mydomain.com/images/comment.gif' border='0' style='overflow:hidden;vertical-align:middle;text-decoration:none;border:0px;outline:none;'>Comment</a>
</div>
<div class='clear'></div>
+4  A: 

OK, you can't use return: false in either click event because that cancels the default and stops event bubbling.

In both your live('click'... and the anchorAnimate click events, use e.preventDefault only.

$('.comm_link').live("click",function(e) {

    ... all your code ...

    // DON'T use return false; Remove it
    e.preventDefault();
});

And:

$(caller).click(function (event) {  
    event.preventDefault();

    ... all your code ...

    // DON'T USE return false; Remove it.
})
Doug Neiner
ummm... where exactly do i put that in place of???
brandon
@brandon Here is your whole snippet (reformatted) with the calls in the right place, and return false removed: http://pastie.org/819003
Doug Neiner
Thanks doug... I pasted the reformatted code and there seems to be a 2 second delay in the scroll animation after clicking comment? Do you know what may be causing that?
brandon
actually it doesn't animate at all it just jumps??? Never used the same class before for two separate events! :-)
brandon