javascript - jQuery show/hide div dont works in Chrome -
i'm novice in jquery. have a.acessaponto if click it, add/remove class a.acessaponto.selected , show/hide div.acessapontoatendimento. have code that. works in firefox , ie doesn't work in chrome.
$( document ).ready(function() { $('.acessaponto').click(function() { $(this).toggleclass('selected'); if ($(this).hasclass('selected')) $('.acessapontoatendimento').css("display", "inline-block"); else $('.acessapontoatendimento').css('display', 'none'); }); });
.acessaponto{ background-color:blue; } .acessaponto.selected{ background-color:red; } .acessapontoatendimento{ display:none; background-color: red; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.min.js"></script> <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>document</title> </head> <body> <a href="#" class="acessaponto">click</a> <div class="acessapontoatendimento"> <p>lorem ipsum dolor color</p> </div> </body> </html>
someone have idea what's problem in code?
$('.acessaponto').click(function (e) { e.preventdefault(); $(this).toggleclass('selected'); $('.acessapontoatendimento').toggle( $(this).hasclass('selected') ); });
in case .acessaponto
on a
tag, need e.preventdefault()
, otherwise not.
Comments
Post a Comment