Reputation: 709
So I have been using raphael to create a user interface and want it so that way if someone clicks on a circle it highlights the circle or does some sort of visually interesting thing to the circle to note that it is selected. I'm not terribly worried about the visual side of this yet. I am trying to figure out a way to make this happen and nothing seems to be working. This is rather simple. At least I thought so but it turns out this has been giving me a nice headache. I would provide code but what I have is a mess right now. If you want it I will add it though.
function elemClick(el)
{
el.click(function(){
circleSelectedArray[0] = true;
});
el.unclick(function(){
circleSelectedArray[0] = false;
});
}
Upvotes: 0
Views: 894
Reputation: 481
You cant bind click and unbind it at the same time ....
el.click(fn) means that you are binding a click event to that element like the way you have which is fine ....
el.unclick(fn) means that you are unbinding a click function from that element.
USE -> if you go like this el.unclick()
all click events will be unbound from that element
if you want to use one function ....
function yourFunc(){
console.log('you clicked me !')}
el.click(yourFunc); // now when you click this el console will show the phrase
//when you unbind the function
el.unclick(yourFunc);
I just have a hunch that you were perhaps trying to use mousedown and mouseup events ....
EDIT : to your requirements
function sel_unsel(){
if(this.data('selected') == false){
this.data('selected', true);
// do here what you want when element is selected
}else if(this.data('selected') == true){
this.data('selected', false);
//do here what you want when element is unselected
}
}
function elemClick(el){
el.data('selected',false);
el.click(sel_unsel);}
Upvotes: 4