/    Sign up×
Community /Pin to ProfileBookmark

Stopping jquery function at second click

Could someone help to ‘how to stop the event at below at second click?

this is a simple photo tagging system..

[U]progress:[/U] when clicking the ‘.button’ link, a ‘#tagdiv’ is sliding down(shows the tag status/tagged names.. i didnt write these codes yet)..
we tag photos at some another div…

when we finished the tagging… we sould click again the ‘.button’; and slideup the #tagdiv(with toggle()?.. and [U]stop the tagging function[/U].. but how?

here is the codes:

[CODE]

<script>
$(document).ready(function(){

var counter = 0;
var mouseX = 0;
var mouseY = 0;

$(“.button”).click(function(e){
$(‘#tagdiv’).toggle(“slow”, function() {
$(‘#imgtag_img’).css(“cursor”,”crosshair”);

$(“#imgtag img”).click(function(e){

var imgtag = $(this).parent();
mouseX = e.pageX – $(imgtag).offset().left;
mouseY = e.pageY – $(imgtag).offset().top;
$(‘#tagit’).remove();
$(imgtag).append(‘<input type=”text” name=”txtname” id=”tagname” class=”sag” /><input type=”button” name=”btnsave” value=”Submit” id=”btnsave” class=”sagbut” /><input type=”button” name=”btncancel” class=”sagbut” value=”Cancel” id=”btncancel” /></div>’);
$(‘#tagit’).css({top:mouseY,left:mouseX});
$(‘#tagname’).focus();

$(‘#tagit #btncancel’).live(‘click’,function(){
$(‘#tagit’).fadeOut();});

$(‘#tagname’).focus(); });

$(‘#tagit #btnsave’).live(‘click’,function(){
name = $(‘#tagname’).val();

$.ajax({
type: “POST”,
url: “savetag.php”,
data: “id=<?=$q[id];?>&name=” + name + “&pic_x=” + mouseX + “&pic_y=” + mouseY + “&type=insert”,
cache: true,
success: function(data){
$(‘#tagdiv’).fadeOut();
viewtag();
}
});

});});
</script>[/CODE]

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@orhunsanauthorMar 14.2012 — should i give more detail about problem?

could someone help me? ?
Copy linkTweet thisAlerts:
@DanInMAMar 14.2012 — im not sure I get you, but if you only want a click function to work once, look into .one()

http://api.jquery.com/one/
Copy linkTweet thisAlerts:
@orhunsanauthorMar 14.2012 — Just think 3 steps..

1) clicking the #button and toggleing(slide down) a div at below..(the div will contain tag names)

2) a special tagging function starts (by the code at next line...).. [B]TAGGING[/B] function..

3) when i click #button again.. 'slide up' div is ok(toggle effect)... [B]but the tagging function is not ending(stil running)... when i click again the button(toggle effect) to slideup; the funnction must stop too..[/B]




im not sure I get you, but if you only want a click function to work once, look into .one()

http://api.jquery.com/one/[/QUOTE]
Copy linkTweet thisAlerts:
@develmacMar 14.2012 — I am having trouble getting the thumbnail scroll to move. The images are just static with the arrows on both ends. Not sure what the problem is. I have add the jquery library in the proper folders. the code I have added is marked in purple



[CODE]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Jewel Computer Brokers inc.</title>

<link href="css/style.css" rel="stylesheet" type="text/css" />

[COLOR="Purple"]<link href="css/jquery.thumbnailScroller.css" rel="stylesheet" type="text/css" />

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>

<script type="text/javascript" src="js/jquery-ui-1.8.13.custom.min.js">
</script>

[/COLOR]
</head>

<body>



<div id="container">




<div id="wrapper">

<div id="main_content">

<div class="mainTop">

<div id="sideNav">
<div id="button1"><div>Service</div></div>
<div id="button2"><div>Hardware</div></div>
<div id="button3"><div>Software</div></div>

</div><!--sideNav-->
<div id="mainBanner"></div>

</div><!--mainTop-->

<div id="home_content">
<p>Satisfying your computer hardware and software needs since 1991. Jewel Computer Brokers&#8217; long term relationship in the computer marketplace enables us to provide you with a full range of computer hardware, software and, supplies. Our top notch service will afford you, the customer the luxury and peace of mind that all of your needs are being taken care of...<span>READ MORE</span></p>

</div><!--home_content-->



[COLOR="Purple"]


<div id="tS2" class="jThumbnailScroller">
<div class="jTscrollerContainer">
<div class="jTscroller">
<a href="#"><img src="images/demo/ibm.png" /></a>
<a href="#"><img src="images/demo/motorola.png" /></a>
<a href="#"><img src="images/demo/ibm.png" /></a>
<a href="#"><img src="images/demo/motorola.png" /></a>
<a href="#"><img src="images/demo/ibm.png" /></a>
<a href="#"><img src="images/demo/motorola.png" /></a>
</div>
</div>
<a href="#" class="jTscrollerPrevButton"></a>
<a href="#" class="jTscrollerNextButton"></a>
</div>
[/COLOR]






</div><!--main_content-->



</div><!--wrapper-->


<div id="footerWrapper">

</div><!--footerWrapper-->



<div id="nav_header">

<div id="navList">

<ul id="nav1">
<li>HOME</li>
<a href="aboutUs.html"><li>ABOUT US</li></a>
</ul>

<ul id="nav2">
<li>SOLUTIONS</li>
<li>CONTACT</li>
</ul>

</div><!--navList-->

<div id="logo"></div>

</div><!--nav_header-->

</div><!--container-->




[COLOR="Purple"]
<script>
/* jQuery.noConflict() for using the plugin along with other libraries.
You can remove it if you won't use other libraries (e.g. prototype, scriptaculous etc.) or
if you include jQuery before other libraries in yourdocument's head tag.
[more info: http://docs.jquery.com/Using_jQuery_with_Other_Libraries] */
jQuery.noConflict();
/* calling thumbnailScroller function with options as parameters */
(function($){
window.onload=function(){
$("#tS2").thumbnailScroller({
scrollerType:"hoverAccelerate",
scrollerOrientation:"horizontal",
scrollSpeed:2,
scrollEasing:"easeOutCirc",
scrollEasingAmount:600,
acceleration:4,
scrollSpeed:800,
noScrollCenterSpace:10,
autoScrolling:20,
autoScrollingSpeed:2000,
autoScrollingEasing:"easeInOutQuad",
autoScrollingDelay:500
});

$("#tS3").thumbnailScroller({
scrollerType:"hoverPrecise",
scrollerOrientation:"vertical",
scrollSpeed:2,
scrollEasing:"easeOutCirc",
scrollEasingAmount:800,
acceleration:4,
scrollSpeed:800,
noScrollCenterSpace:10,
autoScrolling:0,
autoScrollingSpeed:2000,
autoScrollingEasing:"easeInOutQuad",
autoScrollingDelay:500
});

}
})(jQuery);
</script>
[/COLOR]

</body>
</html>
[/CODE]
Copy linkTweet thisAlerts:
@DanInMAMar 15.2012 — I am having trouble getting the thumbnail scroll to move. The images are just static with the arrows on both ends. Not sure what the problem is. I have ad................................
[/QUOTE]


post your own thread for your issue.
Copy linkTweet thisAlerts:
@DanInMAMar 15.2012 — Just think 3 steps..

1) clicking the #button and toggleing(slide down) a div at below..(the div will contain tag names)

2) a special tagging function starts (by the code at next line...).. [B]TAGGING[/B] function..

3) when i click #button again.. 'slide up' div is ok(toggle effect)... [B]but the tagging function is not ending(stil running)... when i click again the button(toggle effect) to slideup; the funnction must stop too..[/B][/QUOTE]


ok so i just took a close look at what you have so far and you have improperly nested pretty much every function there.

paste your code into jshint.org, make sure you check off the jquery option checked and it will help you get it fixed, before you try anything else, i would take care of that first
×

Success!

Help @orhunsan spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...