I have the following code
<a href="" (set value 1)>Inside Link which sets a value</a>
<script>
$(a).click(function() {
i=value of a tag;
$('#square').animate({'left': i * 360});
});
</script>
And i want to add a value attribute to an anchor tag. How to do it?
If you are using HTML5 you can use the
data-
technique.EDIT
Usage of
.data
instead of.attr
is more appropriateIf you want to add a random attribute for a value, you can use data attributes:
<a href="#" data-value="IE" id="click">Click</a>
you can use custom data attributes see this .
then access it using data() function.
Or instead of using json you can put it as an attribute :
then get it using :