Last active
December 31, 2015 21:49
-
-
Save kalkulus/8049203 to your computer and use it in GitHub Desktop.
jQuery: get links by anchor text and extension
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('<div id="JQUERY_URL_LIST"></div>').appendTo('body'); | |
var texts = ["SD","HD","click here"]; | |
var extensions = ['pdf','mp3','m4a','m4v','zip','jpg','png','gif']; | |
var getLinksByText = function(texts){ | |
for(t in texts){ | |
var text = texts[t]; | |
$('a:contains("'+text+'")').each(function(){ | |
var url = $(this).attr('href')+'</br>'; | |
$('#JQUERY_URL_LIST').append(url); | |
}); | |
} | |
} | |
var getLinksByExtension = function(extensions){ | |
for(e in extensions){ | |
var ext = extensions[e]; | |
console.log('a[href$=".'+ext+'"]'); | |
$('a[href$=".'+ext+'"]').each(function(){ | |
var url = $(this).attr('href')+'</br>'; | |
$('#JQUERY_URL_LIST').append(url); | |
}); | |
} | |
} | |
getLinksByText(texts); | |
getLinksByExtension(extensions); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment