0

I have a click event, and within the event handler there's a function that suppose to return a string value

for example:

  $('.customDropDownList li').click(function(){

      var yourCurrentSeasonSelection = selectionReplaced(this);

      //return var yourCurrentSeasonSelection from here.
  });



function selectionReplaced(refT){   
   var valueRegistered = $(refT).find("a[href]").attr('href').replace('#', '');
    ....
   return valueRegistered;
}

How do I get the return value after the click from the yourCurrentSeasonSelection variable?

1
  • you can pass it to another function that will do your view logic. or you can just complete the logic inside the click function. you will probably want to return false; to disable the default click functionality after you have performed the desired action Commented Nov 15, 2013 at 6:39

2 Answers 2

1

Events don't have return values. You can do something like this though

$(".customDropDownList li").click(function(event){
  selectionReplaced(this);
  event.preventDefault();
});

function selectionReplaced(refT){   
  var link = $(refT).find("a[href]");

  link.attr("href", function(idx, href){
    return href.replace("#", ");
  });
}
Sign up to request clarification or add additional context in comments.

Comments

1

You can't "return" the yourCurrentSeasonSelection until the click has actually happened. Anything you want to do with that value has to go inside the click handler.

$('.customDropDownList li').click(function() {
    var yourCurrentSeasonSelection = selectionReplaced(this);

    //do something with yourCurrentSeasonSelection
});

Comments

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.