0

I have a main div called #Content and I replace a data in the #Content based the menu item clicked:

here is the code:

$('.nav-button').on('click', function(e){
e.preventDefault();
$('#content').load($(this).attr('href'));
});
4
  • 1
    I just played around with the sample site - but didn't dive into the code. The behavior we see here is your click event is being added more than once. Look into that, and try using $('.nav-button').unbind('click'); right before you assign the click event. Commented Oct 15, 2012 at 20:31
  • Sorry that doesn't work out @Gallen Commented Oct 15, 2012 at 20:42
  • It'll work - follow Drew's advice for both of your click events. He's just elaborating on my suggestion. Commented Oct 15, 2012 at 21:19
  • @Gallen Yea i followed his code and made the changes, please check. But still no change. Commented Oct 15, 2012 at 21:25

2 Answers 2

2

You're running this binding statement every time you click "Transport":

$(".tsave").live('click',function() {

Try changing it to this:

$(".tsave").unbind('click');
$(".tsave").live('click',function() {

jQuery will append binding statements every time you call them - so, if you bind a click event 10 times to one object, it will run that event 10 times on the event.

Also change this:

$(".save").live('click',function() {

To:

$(".save").unbind('click'); 
$(".save").live('click',function() {
Sign up to request clarification or add additional context in comments.

11 Comments

Hmm - just checked your code, doesn't look like the unbind function is there... Where did you change it? Should be changed on scripts/tran-sheet/data_script.js
@sukarno a comment like "no use" is not only useless, it's also rude. You should always explain how you tried it and what happened, error messages.
I changed the code exactly in the same location u mentioned please check in firebug
Sorry for that but i double checked now!
Looks like you have 2 click events - I think you might use the second one instead of the one I provided above. I've edited the answer to have the second click statement you'll need to unbind for.
|
1

Found answer here:http://forum.jquery.com/topic/jquery-load-loading-a-javascript-in-to-div-calls-a-function-multiple-times

just made a check not to load the script if it is loaded previously. using this simple script:

if (! window.loadedThisScript){
window.loadedThisScript = true
// the whole part of the script that you only want to load one time.
}

credit to: http://forum.jquery.com/user/jakecigar

1 Comment

Cool, make sure you accept your own answer - sorry I didn't get back to you last night.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.