0

I'm currently making an addon for a site, but I stumbled upon a problem: my addon needs to simulate clicking a div, but the div only appears if you're hovering over another div. I tried

$("#id-1").trigger("mouseover");
$("#id-2").click();

but it doesn't really work because the box instantly dissapears again.

is there any way I can do this?

thanks in advance!

edit: $("#id-2") isn't just made invisible, its no longer there in the elements, they're using some code to delete it and put it back in place when you hover over $("#id-1")

3
  • Maybe try $('#id-1:visible').click(); Commented Jan 11, 2014 at 15:07
  • 1
    What does clicking the div do? If it calls a javascript function, can't you just call that? Commented Jan 11, 2014 at 15:08
  • I would have it call the function, but the owners of the site use compressed code, and they update it every few days, and I'm scared that the functions' names are going to change Commented Jan 11, 2014 at 15:12

1 Answer 1

1

If you have access to the CSS file you can use a hover class to do this, assuming they are siblings (could be modified to work with parent-child relationship) and and that they use display:block and display:hidden to hide/show the hidden element

/* CSS */
elemOne:hover ~ div, .hover ~ div { display:block; } // Applies on hover or if 
                                                     // hover class
/* jQuery */
$('elemOne').addClass('hover'); // Initialize the hover state
$('elemTwo').trigger('click');  // Click the now-showing element
$('elemOne').removeClass('hover'); // Remove the hover state

Demo

Sign up to request clarification or add additional context in comments.

2 Comments

sadly I don't have access to the css file, but I already found a way to work around it so I don't have to deal with this :)
I took a completely different approach at the problem, thats why I didn't bother putting it up here, It couldn't really help anyone else.

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.