Sathish Kumar
Sathish Kumar

Reputation: 1

How to assign value to href

i am having menu-bar in that i am using href command how can i add value to link and pass it to next form.

<nav id="nav">
    <ul>
        <li class="current_page_item"><a href="index.php">Home</a></li>
        <li>
            <span>Aptitude</span>
            <ul>
                <a href="#">Technical Questions</a>  // a=5
            </ul>
        </li>
        <li><a href="#">Technical Questions</a></li>
        <li><a href="#">HR Questions</a></li>
        <li><a href="#">Contact Us</a></li>
    </ul>
</nav>

if i click technical question link must contain a value as 5 how can i do these.....

Upvotes: 0

Views: 10742

Answers (2)

dalevross
dalevross

Reputation: 522

You could add a data attribute

<a href="#" data-value="5">Technical Questions</a>

//When it is clicked


 $("a").click(function(){
    val = $(this).data('value') // would be 5
    }

Upvotes: 1

Arun P Johny
Arun P Johny

Reputation: 388446

You can use the data attribute here

<nav id="nav">
    <ul>
        <li class="current_page_item"><a href="index.php">Home</a></li>
        <li>
            <span>Aptitude</span>
            <ul>
                <a href="#" data-elemid="5">Technical Questions</a>  // a=5
            </ul>
        </li>
        <li><a href="#">Technical Questions</a></li>
        <li><a href="#">HR Questions</a></li>
        <li><a href="#">Contact Us</a></li>
    </ul>
</nav>

then in the event handler

$('#nav a').click(function(){
    var id = $(this).data('elemid');
    //do something
})

Upvotes: 0

Related Questions