1

I have the following HTML code:

<td align="center" class="shuttleControl"> 
  <img src="/i/mydb/icons/shuttle_reload.png" onclick="g_Shuttlep_v61.reset();" alt="Reset"  title="Reset"/> 
  <img src="/i/mydb/icons/shuttle_last.png" onclick="g_Shuttlep_v61.move_all();" alt="Move All" title="Move All"/> 
  <img src="/i/mydb/icons/shuttle_right.png" onclick="g_Shuttlep_v61.move();" alt="Move" title="Move" /> 
  <img src="/i/mydb/icons/shuttle_left.png" onclick="g_Shuttlep_v61.remove();" alt="Remove" title="Remove" /> 
  <img src="/i/mydb/icons/shuttle_first.png" onclick="g_Shuttlep_v61.remove_all();" alt="Remove All" title="Remove All" /> 

Based on the above code, using jQuery, how can I replace all the above onclick calls to instead use my JavaScript function get_Count().

So the result I am after is:

<td align="center" class="shuttleControl"> 
  <img src="/i/mydb/icons/shuttle_reload.png" onclick="get_Count();" alt="Reset"  title="Reset"/> 
  <img src="/i/mydb/icons/shuttle_last.png" onclick=" get_Count();" alt="Move All" title="Move All"/> 
  <img src="/i/mydb/icons/shuttle_right.png" onclick=" get_Count();" alt="Move" title="Move" /> 
  <img src="/i/mydb/icons/shuttle_left.png" onclick=" get_Count();" alt="Remove" title="Remove" /> 
  <img src="/i/mydb/icons/shuttle_first.png" onclick=" get_Count();" alt="Remove All" title="Remove All" /> 
</td>

2 Answers 2

6

I'd say something like:

$('img').unbind('click').click(get_Count);

EDIT:

Well, I tried that, and it doesn't work. What does work is .attr('onclick', ''). So, do this:

$('.shuttleControl img').attr('onclick', '').click(get_Count);
Sign up to request clarification or add additional context in comments.

6 Comments

@Spiny, I have other img tags throughout my code so how can I pin point to ensure that I am only referencing the shuttleControl class?
.unbind() is for jQuery handlers.
@tonsils I edited my post, this should work for you. @patrick Yeah, I just found out about that :)
@Spiny - I think this has worked - still testing it. Just another query, how would I target just one line only, say the shuttle_last.png line and only change the onclick call for this line alone? Thanks.
@tonsils Well, since the imgs don't have an id, you'd have to use one of the other selectors (api.jquery.com/category/selectors), for example: $('.shuttleControl img[src="/i/mydb/icons/shuttle_last.png"]') (or: $('.shuttleControl img[src$="shuttle_last.png"]'))
|
0

If you're not needing those functions in g_Shuttlep_v61 at all, you could just overwrite them.

g_Shuttlep_v61.reset = 
g_Shuttlep_v61.move_all = 
g_Shuttlep_v61.move = 
g_Shuttlep_v61.remove = 
g_Shuttlep_v61.remove_all = get_Count;

Then there's no need to mess with the inline attributes.

2 Comments

thanks. where exactly in the code would I set these calls to now use my get_Count call?
@tonsils: I assume g_Shuttlep_v61 is a global variable, so just place it in the same scope as your get_Count function.

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.