I'm not understanding something here. This gives an error "undefined is not a function" for line 5. I want to add a class to every link that has ".mp3" but does not have ".php".
jQuery(document).ready(function(){
jQuery('a[href$=".mp3"]')
.each(function()
{
if (this.toString().indexOf(".php")<0) { $(this).addClass('sm2_button');}
});
var btn = jQuery('<span class="btn-pressplay"> </span>');
jQuery('.sm2_button').prepend(btn)
});
Edit: I also tried the following per @user3659034. The error I get is Type error: undefined is not a function console.log produces "a#page-top" so looks like I'm trying to evaluate a weird a on my page that I need to exclude. I got the typeof code from here.
jQuery(document).ready(function(){
//edit NEB
//jQuery('a[href$=".mp3"]').addClass('sm2_button');
jQuery("a").each(function(idx) {
console.log (this);
var attr = $(this).attr('href');
if (typeof attr !== typeof undefined && attr !== false) {
if (jQuery(this).attr('href').indexOf(".mp3") > -1) {
if (jQuery(this).attr('href').indexOf(".php") == -1) {
jQuery(this).addClass('sm2_button');
}
}
}
});
var btn = jQuery('<span class="btn-pressplay"> </span>');
jQuery('.sm2_button').prepend(btn)
});
This is for the pressplay-lite wordpress plugin to limit changing mp3 links that are downloads instead of mp3s.