Hitesh Chauhan Hitesh Chauhan - 13 days ago 8
Javascript Question

is it possible to set javascript:void(0) with #map for tabs in href?

i want to set JavaScript:void(0) with #map tabs in h ref. i want to set JavaScript:void(0) which is responsible for not to load the webpage on click. #map is tab .so i want to set both JavaScript:void(0) and #map. check here

my code is

<li><a data-toggle="tab" href="#map" href="javascript:void(0)" onclick="getvalue('+val['product_id']+');" id="maptab">map</a></li>

Answer

No need to use both actually you can use .preventDefault() when you write javascript function for this <a>.

$('li a').click(function(e){
  e.preventDefault();
  //... other code of function
})

.preventDefault() prevents the default function of the element. so the page load will be prevented with this.