combine click and change for one execution
I need to execute the same code for both a link click and change event
- <img class="foo" name="54321" src="http://jsfiddle.net/img/logo.png" >
- <br><br>
- <select class="bar" name="12345" size="1">
- <option value="0">0</option>
- <option value="1">1</option>
- </select>
- $(".foo").click(function() {
- //same code
- }
- $(".bar").change(function() {
- //same code
- }
- $('. foo , .bar').on('click change', function() {
- alert ($(this).attr('name'));
- });
If I click on the selectbox, I get the messagebox before I change the value.
Anybody an idea?