jquery and browser fake clicking

396 Views Asked by At

I know that the browsers don't support fake clicking. I know I can go back and just start refactoring out all of the obtrusive javascript... but that won't happen. With that being said...

Heres the thing.

I have a bunch of links that represent preferences. EX: (this is rendered content. The actual jsp that creates this below is not fun to look at.)

<table id="snTabsAvail" class="content" cellspacing="5" cellpadding="1" border="0" align="center">
<tbody>
  <tr>
    <td id="Serial Number_Engine Test_0" class="tbutton" width="95px" nowrap="" height="55px"  style="background-color:lime">
      <a href="javascript:tabToggle('Serial Number', 'Engine Test', spref, 0, tabPicked, tabAvailable, 'Failed to update your tab preference, please try again later'); ">
    </td>
    <td id="Serial Number_Machine Test_1" class="tbutton" width="95px" nowrap="" height="55px" style="background-color:lime">
      <a href="javascript:tabToggle('Serial Number', 'Machine Test', spref, 1, tabPicked, tabAvailable, 'Failed to update your tab preference, please try again later'); ">
   </td>
...

These calls represent Ajax calls, which set preferences on the server. I want to include a select all and a deselect all so I dont have to go and click all of them individually. I know I cant do this

$('#snTabsAvail td[style=background-color:silver] a').click();

Due to the fake clicking issue.

Since these are clicks represent javascript ajax calls, I'm trying to figure out how to click the ones I want for select, unselect. the cells that the links are in represent 'tabs' and you can tell which ones are selected by their background color... which is why I said, anything cells in this table with the unselected background color, get the anchors, and click, which doesn't work.

Any thoughts on how to get all the anchors here and fake click them? Yes.. I mean programmaticlly.

1

There are 1 best solutions below

1
On

You can use eval() on the href attribute of each link (not sure if have to remove the "javascript:" part), like this:

eval($('#snTabsAvail a').attr('href').substring(11));

Edit: of course this is for a single link, you have to iterate over the elements returned by $('#snTabsAvail a') for the complete solution.