admin管理员组

文章数量:1334309

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.

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.

Share Improve this question edited Mar 25, 2017 at 7:54 Mihai Alexandru-Ionut 48.4k14 gold badges105 silver badges132 bronze badges asked Feb 5, 2017 at 14:07 A191919A191919 3,4627 gold badges55 silver badges102 bronze badges 1
  • 4 What hidden element? I don't see any hidden elements above (no pun). – T.J. Crowder Commented Feb 5, 2017 at 14:13
Add a ment  | 

2 Answers 2

Reset to default 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./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>

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.

本文标签: javascriptJquery click on hidden elementStack Overflow