How to simulate click on another HTML element?

Asked

Viewed 311 times

1

In this image below it is normal now, but every time I pass the mouse over it is placed the element figcaption in the image, that figcaption I used to paint the picture black.

Here, the image before I move the mouse with your $('img')

After I pass the mouse over she gets one figcaption over her, because I used that figcaption to paint in black.

Image with the $('figcaption') active.

My question is: How can I click on the image and select the $('img')?

I don’t want to select the figcaption which is on top of the image, because with it I won’t be able to open my photo box.

$('img').bind('click',function() { $(this).$('caixabox').show('slow') } 
);
  • 2

    Put the html code as well and what has been done to make it easier for us to help

3 answers

0

Suggestion, the image should be darkened even, or it could be lightened?

A very easy option is to use the opacity of css, example:

<img src='suaimagem.jpg' class='altera-opacidade' >

there in the css file

.altera-opacidade{
    opacity: 0.5;  //sem o mouse em cima fica clarinha
    //filter:grayscale(100%); se quiser testar preto e branco
    //filter:blur(5px); //se quiser testar embaçado
}
.altera-opacidade:hover{
    opacity: 1.0  //com o mouse em cima fica normal e nao atrapalha o que voce quer fazer
    //filter:grayscale(0); //volta a cor
    //filter:blur(0px); //volta a nitidez
}

still suggest testing other effects, with Blur instead of opacity, personally I think it gets even more beautiful. Then, of course, in my example, you will no longer use the figcaption. Good luck!

0

It gets easier with your code, but I can tell you that if you put in your CSS pointing to yours figcaption the following CSS: pointer-events: none;, do as you wish. Your figcaption will not have mouse events, and instead, the click will go straight to the back element.

Example:

figcaption {
    pointer-events: none;
}

div {
	position: relative;
	display: block;
	width: 367px;
	height: 314px;
}

figcaption {
	position: absolute;
	top: 0;
	left: 0;
	display: none;
	width: 367px;
	height: 314px;
	background: rgba(0,0,0,0.2);
	pointer-events: none;
}

div:hover figcaption {
	display: block;
}
<div>
  <a href="#"><img src="https://i.stack.imgur.com/ZYtPu.png" /></a>
  <figcaption></figcaption>
</div>

EDIT:

As remembered by @Brunnovianna, pointer-events will not work in IE versions below IE11.

  • vc have Whats or skype? n to getting ;/

  • 1

    Note that Pointer-Events is only served by IE11+ browsers. Source: https://caniuse.com/#search=Pointer-Events

  • 1

    @Brunnovianna Well remembered. I can’t speak for everyone, but I usually don’t care much for it. Hahaha... But it’s well spoken for those who care. I’ll update the answer.

0

It would be good to provide the structure of html so we can better understand how to do it. But if you are using the "default" structure for tags <img> and <figcaption> (that is, whereas the $('figcaption') is at the same level as the image):

$('figcaption').on("click", function(e){
    e.preventDefault();
    e.stopPropagation();

    $(this).siblings("img").click();
});

The structure would need to look something like this:

<figure>
    <img src="imagem.jpg">
    <figcaption>Figcaption</figcaption>
</figure>

If that mark is NOT similar to yours, post the mark and edit the answer.

  • Do you have skype or Whats or email me to send you the code? help me pfpf

  • @Jessicajadex Already got the help?

  • Qque is stoppropagation and siblings?

  • Event.stopPropagation() prevents the event from "climbing" to other elements. When you click on an item, it does an event called "Bubbling" and can cause an unwanted click on other elements. siblings you use to select elements that are "siblings" of the element in reference (i.e., are on the same level and within the same node).

  • About Bubbling: https://stackoverflow.com/questions/4616694/what-is-event-bubbling-and-capturing

  • About the method . siblings: https://api.jquery.com/siblings/

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.