Alex G. Alex G. - 5 months ago 6x
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?


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});