I want to append a code after all links with mp3 extension in a specific div.
Here is the code I am trying :
$("#Temp_Div").find('a[href$="mp3"]').append('<a class="mp3play" href="javascript:Play('+ $(this).href +');"></a>');
The problem is $(this).href It doesn’t return the href of link. it returns undefined
If
thisis a DOM object you should just be using:The (more verbose, less efficient) jQuery way of writing it would be:
In any event, the
.append()call won’t work as written becausethisisn’t actually being set at all.You need to call
.each()with the matched elements with a callback function. jQuery will then ensure thatthisis set to the current DOM object.Like this: