jQuery error not visible when migrating code

Asked

Viewed 129 times

1

Well, I have on the following page

http://www.hotplateprensas.com.br/estilos/aa2.php

The functional script

When I migrate to the end of the page:

http://www.hotplateprensas.com.br/estilos/index.php

Then the following errors occur:

1 ) I can no longer click on li’s

2 ) No longer appears the effect of inter (little hand) when passing the mouse over the li’s

I’ve tried everything but I’m not getting it.

And there’s something else:

http://www.hotplateprensas.com.br/estilos/aa2.php

Does not work in the chrome, only in firefox

Here is the code of Aa2.php

<script type="text/javascript" src="_js/jquery.js"></script>

CSS

@charset "utf-8";
/* CSS Document */

* {
    margin: 0;
    padding: 0;
    font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
    font-size: 14px;
}
body {
    margin: 0 auto;
    width: 800px;
}
.selectOptions select {
    display: none;
}
.selectOptions .selectOption:after {
    position: absolute;
    content: "";
    display: block;
    top: 1px;
    right: 1px;
    width: 33px;
    height: 33px;
    background-image: url(_imgs/setaBaixo.jpg);
}
.selectOptions .selectOption.setaBaixo:after {
    background-image: url(_imgs/setaBaixo.jpg);
}
.selectOptions .selectOption.setaCima:after {
    background-image: url(_imgs/setaCima.jpg);
}
.selectOptions .selectOption, ul {
    position: relative;
    width: 200px;
    height: 35px;
    background-color: rgba(0,0,0,0.2);
}
.selectOptions ul {
    overflow: hidden;
    list-style: none;
    z-index: -1;
}
.selectOptions ul li {
    width: 100%;
    height: 31px;
    line-height: 31px;
    cursor: pointer;
    padding: 2px;
    color: rgb(255,255,255);
    background-color: rgb(240,240,240);
    border-bottom: rgba(0,0,0,.1) 1px solid;
}
.selectOptions ul li:hover {
    color: rgb(255,255,255);
    background-color: rgba(0,0,0, .1);
}
.selectOptions ul li:hover + .selectOption:after {
    color: rgba(0,0,0, .1);
    background-color: rgb(255,255,255);
}

HTML

<div class="selectOptions">
  <select name="select" required>
    <option value="1">um</option>
    <option value="2">dois</option>
    <option value="3">Tres</option>
  </select>
  <div class="selectOption">
    <ul>
    </ul>
  </div>
</div>

jQuery

$(document).ready(function(e) {

  $(".selectOptions select").css("display", "none");

  contador = 0;

  $(".selectOptions .selectOption").click( function() {

      if(contador % 2 == 0) {
          $(".selectOptions ul").css("overflow", "visible") ;
          $(".selectOptions .selectOption").addClass("setaCima").removeClass("setaBaixo");
      } else {
           $(".selectOptions ul").css("overflow", "hidden");         
          $(".selectOptions .selectOption").addClass("setaBaixo").removeClass("setaCima");
      }

      $('.selectOptions .selectOption ul li').click(function(){ 
      alert();    
           $($(this).closest('ul')).prepend($(this)); 

           $(".selectOptions select option").filter(function() {
              return $(this).val() == $('.selectOptions .selectOption ul li').val();
           }).prop("selected", true);

      })

      contador++;
  }); 


  $(".selectOptions select > option").each(function() {
      $(".selectOptions .selectOption ul").append("<li id="+this.value+">"+this.text+"</li>");
  });

});

One thing I noticed is that in index.php, when you get here:

$('.selectOptions .selectOption ul li').click(function(){ 
  alert();    

Does not enter the function, can put a Alert on the first line that doesn’t alert. You can leave it alone Alert within the function that nothing happens.

This for both browsers, Chrome and firefox.

However, for the file Aa2.php, the error only occurs for the Chrome.

But another thing I noticed is that in css, cursor:Pointer is not working for the page index php. in the 2 browsers already on the page Aa2.php the cursor works.

  • You’re using browser compatibility mode in your css -webkit- and -moz-?

  • What do you mean? Please explain?

1 answer

1


inserir a descrição da imagem aqui In the above print, when I step the pointer to select elements over the menu, it selects the body (in blue) instead of selecting the menu.

Your problem is in the z-index below negative, which is playing the <ul> behind the body:

.selectOptions ul {
    overflow: hidden;
    list-style: none;
    z-index: -1;
}

Delete the line z-index: -1; which will work on Chrome as well.

  • I couldn’t see that the menu is behind me. Can you give me a print of this screen please?

  • @Carlosrocha I put a print on the answer.

  • Get it, note that you are passing the mouse over the ul open and second option on. In this case, you are on top of a pseudo element Afer that is not yet in the gift. Therefore the inspector marks the body. I think that’s it. But I’d like you to send me that detail from the beginning of post where do you say that the div is over the menu

  • @Carlosrocha So it is. In Chrome the menu is below, why it does not work. With z-index I managed to bring it up and it worked. In Firefox it worked without z-index. It means that your code is not very good. It is very difficult to happen browser incompatibilities for simple things like this. When this occurs, it is a sign that the code is not legal.

  • @Carlosrocha Your problem is with CSS .selectOptions ul with z-index: -1;... Take it out and it’ll work.

  • I did this in order not to allow selection on the first element and it worked. But it worked wrong right/ This was supposed to be a select option

  • @Carlosrocha exactly.

  • @Carlosrocha If you want to disable the first option to click, just change the line $('.selectOptions .selectOption ul li:not(:eq(0))').click(function(){

  • worked! Thank you!

  • Boy, solved one problem and created another. Now, the two arrows are not changing with the after, that is, only appearing the down arrow. I updated there on the server. If you can take a look at it please?

  • @Carlosrocha In CSS, the last two classes need to be united, like this: .selectOptions .selectOption.setaCima:after. Note that there cannot be a space between the last two classes. Do the same on the line where you have .setaBaixo.

  • Yes it worked. Thanks. But tell me, was it cool the little project of this select option that I created? Needs to improve the look right?

  • @Carlosrocha It was cool. I’m trying to figure out the effect "roll" you said in the other question.

  • So I found another problem, too. kkk, when I cliko out of ul, I would like you to close it, overflow it:Idden, but nothing I tried worked out. Actually, it worked, but it gets in the way of other things.

  • @Carlosrocha I will see this too. But I wonder if I can put the link of the site there in the other question for my answer have code reference.

  • but of course it can. The problem is that as soon as I finish, I will need to delete because the site is not mine, it is customer’s. But it can yes.,

  • @Carlosrocha The thing about clicking off and closing the menu, add this above the line where you have it contador++: e. stopPropagation();

  • @Carlosrocha Better view all the code in this Fiddle: https://jsfiddle.net/vjzogcw9/1/

Show 13 more comments

Browser other questions tagged

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