how to remove # from href value in jquery

Actually I need to remove '#' from href value, I had used replace method but its not working. Suppose I get value in targetId=#general1,from that I need to remove # and i need to append it to another class.

$(document).ready(function() {    
    $('.dropdown-menu li a').click(function() {    
        var targetId = $(this).attr('href');    
        $('#activepage').text(targetId);
    });
})

Answers 1

  • FIDDLE

    $(document).ready(function(){
    
        $("a").click(function(){
            alert($(this).attr("href").replace("#",""));
    
        });
    
    });
    

    This will work fine though it will replace all #


Related Articles