The reason they do not match is because attr('value') gets the value of the value attribute directly from the HTML source code, does not update from the DOM , which means that if the value from value changes after the page loads or by input by the user (input to the <input> element, or by manipulating JavaScript, these changes will not be displayed in the returned .attr() value.
It is best to use the .val() method of the jQuery object.
Edit To get a value attribute from a DOM element (i.e. not returned by the $() or jQuery() function), use the element.getAttribute() method, which is native, you would use it like this:
selectbox.options[selectbox.selectedIndex].getAttribute("value");
source share