Search code examples
jqueryhref

jquery rule for href with # only


How to apply a rule on a class .button that have a href of "#" only

in fact, any button with a real href will do his button thing, the other one, onother thing

just to clear thing

$(".jbutton").click( function () {

i like that function to be executed on anything BUT #... exclude #

is it more clear ?


Solution

  • Live Demo

    http://jsfiddle.net/Jaybles/nEdHH/

    HTML

    <button href="#" id="button0"></button>
    <button href="123" id="button1"></button>
    <button href="123" id="button2"></button>
    

    JS

    $('button[href!="#"]').click(function(){
        alert($(this).attr('id'));
    });