I find jQuery difficult to learn because there seem to be many ways to write the same thing.
As an exercise, I would like to take the text in the anchor tags and fill it with the href link attribute.
eg,
<a href="">http:
to become
<a href="http://www.something.com">http:
my first attemp was
<script type="text/javascript">
$(document).ready(function() {
var text = $('a').text();
$('a').attr( 'href', text );
});
</script>
which clearly does not work, since I need to specify for this action for each link.
Should I use a foreach loop? Function .each ()? Or is $ this designation? Will they all work?
source
share