Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript version of this jQuery line [closed]

I am searching for a javascript alternative for the following code:

$('a[href*="vivo.sx/"]').attr('href')

I have never worked with javascript. This may be very simple for someone who's more experienced with javascript.

like image 633
Austyn Mitchell Avatar asked Oct 17 '22 23:10

Austyn Mitchell


1 Answers

I've done a version that does it both way for comparison..

Please note I've used document.querySelector, not document.querySelectorAll, if you use the All variant, remember you need to loop the result.

console.log( $('a[href*="vivo.sx/"]').attr('href') );
console.log( document.querySelector('a[href*="vivo.sx/"]').href );
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a href="http://www.vivo.sx/tester">one</a>
like image 101
Keith Avatar answered Nov 02 '22 07:11

Keith