Jishnu V S Jishnu V S - 5 days ago 6
HTML Question

disable anchor tag first click on devices and need to work second click

I have a DOM like this. when i click the anchor tag first time on devices i want to disable the anchor tag. and second click it will go to the url, good answers must be appreciated.



$(function(){

var oreintedWidth = $(window).width();
if (oreintedWidth < 1200) {
var $clickLinks = $('.social').find('ul').children('li');
$($clickLinks).on('click', 'a', function(events){

$($clickLinks).each(function(index, element) {
$(this).closest('li').removeClass('selected');
});

$(this).closest('li').addClass('selected');
if($(this).closest('li').hasClass('selected')){
events.preventDefault();
}else {}
});
}

});

<div class="social">
<ul>
<li><a href="about.html" target="_blank">one</a></li>
<li><a href="about.html" target="_blank">two</a></li>
<li><a href="about.html" target="_blank">three</a></li>
</ul><!-- /.ul -->
</div>




Answer

yes i got it. this is what i am looking for , thanks for the support

$(function(){

    var oreintedWidth = $(window).width();
    if (oreintedWidth < 1200) {
    var $clickLinks = $('.social').find('ul').children('li');
    	$($clickLinks).find('a').attr('onClick','return false');
    	$($clickLinks).on('click', 'a', function(events){
    		var nearBy = $(this).closest('li');
    		
    		$($clickLinks).each(function(index, element) {
                $(this).removeClass('selected');
    	        $(this).find('a').attr('onClick','return false');
            });
    		
    		nearBy.addClass('selected');
    		if(nearBy.hasClass('selected'))
    		{
    			$(this).attr('onClick',"return true");
    			
    		}
    		else {
    			$(this).attr('onClick','return false');
    			
    		}
    		
    		
    	});
    }
    });