javascript - Jquery click event inside an anchor tag -


i using bootstrap css styling , responsive site.

i created default panel bootstrap , entire panel made clickable anchor tag open in new tab. however, there needs close icon dismiss panel; , using javascript same. problem arises when click on close icon - though panel dismissed, having new tab opened due anchor tag. there way avoid new page opening.

code looks this:

<div class="panel panel-default">   <div class="panel-body">     <a href="#" target="_blank">       <p>basic panel example</p>       <button type="button" class="close" id="close">&times;</button>     </a>   </div> </div> 

so have javascript dismiss panel id="close". clicking same though, results in anchor redirect. 1 possible way use css relative positioning of closing icon outside anchor tag. getting messed requirement smaller size screen.

how can accomplish javascript?

if understand correctly have call method preventdefault on event object.
here can find specification: jquery preventdefault

so have this:

$("#close").click(function(e) {     e.preventdefault();     $("#mypanel").close();  }); 

i re-create case here: http://jsfiddle.net/x4nu0whw/
hope helps!


Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -