1

I have

<table width="60" height="60" cellpadding="0" 
cellspacing="0" border="0" style="float: left; margin: 1px" 
background="images/data/source_red.gif">
   <tbody>
      <tr>
         <td act1="7" act3="8" store="true" art_id="4949" cnt="1" div_id="AA_4949" 
         onmouseover="artifactAlt(this,event,2)" 
         onmouseout="artifactAlt(this,event,0)" 
         valign="bottom" 
         style="background-image: url(&quot;images/d.gif&quot;); cursor: pointer;">&nbsp;</td>
      </tr>
   </tbody>
</table>

I want to make click on the element that rises when onmouseover="artifactAlt(this,event,2)"is firing, how to do that?

When I am doing $('#body').contents().find('td[art_id="4949"]')[0].click();

i get undefined and nothin happens.

Mihai Alexandru-Ionut
  • 47,092
  • 13
  • 101
  • 128
A191919
  • 3,422
  • 7
  • 49
  • 93

2 Answers2

7

You should use .click() method.

function artifactAlt(obj,event,number){
     $(obj).click();
}

function artifactAlt(obj,event,number){
   $(obj).click();
}

$('tr').click(function(){
  alert('tr clicked');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table width="60" height="60" cellpadding="0" 
cellspacing="0" border="0" style="float: left; margin: 1px" 
background="images/data/source_red.gif">
   <tbody>
      <tr>
         <td act1="7" act3="8" store="true" art_id="4949" cnt="1" div_id="AA_4949" 
         onmouseover="artifactAlt(this,event,2)" 
         onmouseout="artifactAlt(this,event,0)" 
         valign="bottom" 
         style="background-image: url(&quot;images/d.gif&quot;); cursor: pointer;">abcd</td>
      </tr>
   </tbody>
</table>
Mihai Alexandru-Ionut
  • 47,092
  • 13
  • 101
  • 128
0

You should try jquery trigger's as follows

function artifactAlt(element, event, number) {
  $(element).trigger('click');
}

Usage of trigger('click') will save you one function call as jQuery internally calls trigger for a $().click() function call as pointed out in this post.

Community
  • 1
  • 1
faizal vasaya
  • 517
  • 3
  • 12