0

I need to add a jquery script into a javascript function and then call that function when #sortby is added to the url. Is this possible?

the jQuery

$("#myselect option[value='availability']").attr("selected","selected");

the Javascript

function sortBy(){
    performanceQuery(perfpage);
    tourQuery(tourpage);
    return false;
}
2
  • 3
    The jquery code is also javascript code. Commented Aug 16, 2012 at 11:01
  • I'm not sure what the problem is. jQuery is valid javascript, so there is not issue whatsoever in mixing the two. Also, presumably, "when #sortby is added to link" -> you mean that someone clicks on a link with that achor tag? This is a simple click event. I would suggest to check docs.jquery.com/Tutorials:How_jQuery_Works as this is basic jQuery stuff. Commented Aug 16, 2012 at 11:03

2 Answers 2

1
$(window).on('hashchange', function() {
    if (document.location.hash == '#sortby') sortBy();
});

function sortBy(){
    $("#myselect option[value='availability']").prop("selected", true);
    performanceQuery(perfpage);
    tourQuery(tourpage);
    return false;
}
Sign up to request clarification or add additional context in comments.

Comments

1

jQuery is just a Javascipt library that provides some new functions (yes, this $ is just a funky name of a variable containing function). You can use it wherever you want.

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.