-1

I would like to create a function in jquery which simulates onMouseOver event of a specific element on the page. And then call it with a html button like this

onclick="myFunction()"
I've been searching for a solution now for a while and just couldn't figure it out. Do anyone have solution? or is it easier to make javascript? Kind regards
Ravi Patil
  • 127
  • 2
  • 16
Fippe
  • 41
  • 3
  • i dont know what you are trying to do here, if you wrap your onMouseOver to a function, u could call it in onClick of your Button too. If you are trying to make your cursor moves to specific element when click a button, i dont think you can do that in JS. – Vin.X Mar 02 '18 at 03:50

2 Answers2

0
$("#yourid").on('mouseover', function() {
   // do something
});
Gaz
  • 9
  • 2
  • ”yourid” is that where I put the specific element I want to simulate hover/mouseover on? – Fippe Mar 02 '18 at 02:49
  • 1
    While this code snippet may solve the question, [including an explanation](http://meta.stackexchange.com/questions/114762/explaining-entirely-code-based-answers) really helps to improve the quality of your post. Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion. – 31piy Mar 02 '18 at 04:52
0

I did not understand, would it be something like that? I put the mouse over or hover event, to make it easier if you need to.

<div class="wrapper" style="width:200px;height:200px;background:red">

</div>
<button id="myButton">my button</button>

__

$('.wrapper').hover(function(){
  console.log('mouse in');
},function(){
  $('#myButton').click();
});

$('#myButton').click(function(){
  alert('clicked button')
})
  • Ah, can’t I call the function in the html button with: – Fippe Mar 02 '18 at 02:51
  • imagining that its function is myFunctions (e) { console.log (e.target) } you could call it so onclick = "myFunction" because "myfunction" is a callback function, ie the jquery event will execute and "myFunction ()" you are calling this function for execution – Kelvin Silva Mar 03 '18 at 04:31