Calling Javascript Function in wordpress menu

in my html website I can call any javascript function through anchor like this

<a href="javascript:function();"></a>

but when I try to add this in wordpress menu option then after saving menu , everything vanished from there and field becomes empty. how can I call functions through wordpress Menu’s.

Read More

any one can help please ?

Related posts

Leave a Reply

1 comment

  1. It’s hard to say what the problem is without seeing your JS, but you could try this:

    <ul>
        <li><a id="red" href="#" onclick="myFunction()">List Item with Function</a></li>
        <li><a href="#">List Item without Function</a></li>
    </ul>
    
    function myFunction(){
        document.getElementById('red').setAttribute('style', 'color: red');
    }
    

    Here’s a fiddle: http://jsfiddle.net/BSshG/1/

    Or handle the click even with JavaScript and don’t worry about changing the HTML:

    document.getElementById('red').onclick = function(){
        this.style.color = "red";
    }
    

    Another fiddle: http://jsfiddle.net/BSshG/2/