1

i am trying to add a new event to the select box, i had seen many jquery codes here on stackoverflow, but the one does not seems what i am trying to do:

here is my code try:

if ($("#Filters").find("select[multiple='multiple']").length != 0){ 
  $("#Filters").find('select[name="myselect"]').removeAttr('onChange');
  $("#Filters").find('select[name="myselect"]').attr('onChange','onmultipleoptions');               
}

I want to remove the onchange and then add again the onchange with new function called as onmultipleoptions()..

Guide

1 Answer 1

1

You have a syntax error when creating the new onChange.

Change

.attr('onChange','onmultipleoptions')

to:

.attr('onChange','onmultipleoptions()')

You could accomplish binding the new event handler using jQuery .change(onmultipleoptions) or .on('change',onmultipleoptions) instead of replacing the attribute

DEMO

Sign up to request clarification or add additional context in comments.

1 Comment

Yup, way better using jQuery event listeners.

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.