JavaScript version of this jQuery string

I am looking for an javascript alternative for the following code:

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

I have never worked with javascript. It can be very simple for those who are more versed in javascript.

+5
source share
1 answer

I made a version that does this as a comparison.

Please note: I used document.querySelector, not document.querySelectorAll, if you use the "All" option, remember that 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> 
+3
source

Source: https://habr.com/ru/post/1258571/


All Articles