execute function in before and after content

Asked

Viewed 182 times

2

I have a before and after in a div with their respective meet.

Would like to click on in that content and perform a function jQuery.

It is possible?

I tried it the way down but it didn’t even work alert:

$(document).ready(function(e) {
      $(".slideShow ul:nth-child(1)::before").on("click", function() {    
      alert();
          index = $(this).index() + 1;
          $(".slideShow ul:nth-child(1) li").css("display","none");
          $(".slideShow ul:nth-child(1) li:nth-child("+index+")").css("display","block");
      });   
 });

HTML

<div class="slideShow">
  <ul>
    <li><img class="aberturaSelect" src="_imgs/_slideShow/1.png" /></li>
    <li><img class="aberturaSelect" src="_imgs/_slideShow/2.png" /></li>
    <li><img class="aberturaSelect" src="_imgs/_slideShow/3.png" /></li>
  </ul>
  <ul>
    <li>1</li>
    <li>2</li>
    <li>3</li>
  </ul>
</div>

CSS

* {
    margin: 0;
    padding: 0;
    /*outline: none;*/
    border: none;
    font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
    color: rgb(150,150,150);
}
body {
    font-size: 14px;
}
ul {
    width: 100%;
    list-style: none;
}
.aberturaSelect {
    -webkit-transition: 3s ease 2s;
    -moz-transition: 3s ease 2s;
    -o-transition: 3s ease 2s;
    transition: 3s ease 2s;
}
.slideShow {
    width: 100%;
}
.slideShow ul:nth-child(1)::before {
    position: absolute;
    left: 20px;
    top: 150px;
    content: url(_imgs/setaEsquerda.jpg);
    opacity: 0;
}
.slideShow ul:nth-child(1)::after {
    position: absolute;
    right: 20px;
    top: 150px;
    content: url(_imgs/setaDireita.jpg);
    opacity: 0;
}
.slideShow ul:nth-child(1):hover::before, 
.slideShow ul:nth-child(1):hover::after {
    opacity: 1;
    cursor: pointer;
}
.slideShow ul:nth-child(1) li {
    display: none;
}
.slideShow ul:nth-child(1) li:nth-child(1) {
    display: block;
}
.slideShow ul:nth-child(1) li img {
    width: 100%;
}
.slideShow ul:nth-child(2) li {
    display: inline-block;
    width: 30px;
    height: 30px;
    line-height: 30px;
    background: rgba(0,0,0,.5);
    color: rgb(255,255,255);
    text-align: center;
    cursor: pointer;
}
  • 1

    No way to manipulate pseudo-elements with JS.

  • any other resource? Something with CSS maybe?

  • Not only putting the elements into html manually. See this question related in Soen

  • You can change the class. Create classes with ::before and change using jQuery.

  • Ex.: .div_visivel::before { display: block; } and .div_oculta::before { display: none; }

  • There in jQuery you make the exchange of one for another in the element.

  • I don’t understand how this can help: I need to run a jQuery function. Can explain it better by doing favor?

  • Post in question the CSS of this ::before.

  • done. I put at the end of the question

  • I saw that you put the arrows as :after and :before. The best is to do this with span, because you can capture clicks on them. I made a Jsfiddle with changes in your code, CSS and JS (the images put any one just to illustrate): https://jsfiddle.net/tgs5m6a2/

  • 1

    As their pseudo-elements are positioned, it is even possible to calculate where they are and compare them to the position of the click. But if it is possible to use real html elements that everything becomes simpler.

Show 6 more comments
No answers

Browser other questions tagged

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