Search all iframe srcs with jquery

Is there a way, with jquery, for exapmle when clicked, to find all iframe elements, remove their src = tag and return it? like, update :)

Looking for a foreach function or something like that, but I'm pretty hopeless about that :(

Thanks for your time, Mart

+7
source share
4 answers
$(document).ready(function() { $('#somebuttonid').click(function() { $("iframe").each(function() { var src = $(this).attr('src'); $(this).attr('src', src); }); }); }); 
+8
source

You can update all iframes like this

 $("iframe").each(function() { $(this).attr('src', $(this).attr('src')); }); 
+3
source

You can pass the function .attr() [docs] (or .prop() [docs] ):

 $('iframe').attr('src', function(index, val) { return val; }); 

This function is performed for each item. This is a bit more concise than using an explicit .each loop.

+2
source

You don't even need jQuery:

 for(var i = 0; i < frames.length; i++) { frames[i].src = frames[i].src; } 
+2
source

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


All Articles