Alex G. Alex G. - 2 years ago 62
Javascript Question

How to add a certain value to anchor tag?

I have the following code

<a href="" (set value 1)>Inside Link which sets a value</a>

$(a).click(function() {
i=value of a tag;
$('#square').animate({'left': i * 360});


And i want to add a value attribute to an anchor tag. How to do it?

Answer Source

If you want to add a random attribute for a value, you can use data attributes:

<a href="#" data-value="1">Text</a>

<script type="text/javascript">
    $('#square').animate({'left': i * 360});
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download