On click load iframe

I have this html

a href=#1647278006925-e8321147-313b data-vc-accordion= data-vc-container=.vc_tta-containerspan class=vc_tta-title-textLISTEN/span/a

that is printed in my page and opens an accordion with an iframe in it. The iframe:

iframe id=myiFrame class=stop-lazy data-src=https://some.iframe frameborder=0 allowtransparency=true style=width: 100%;min-height: 150px;/iframe

I am trying to create a jquery code that will load the iframe only when the user click on the link. So i have tried to set the below script in the footer.php:

script $(.vc_tta-title-text).click(function(){ var iframe = $(#myiFrame); iframe.attr(src, iframe.data(src)); }); /script but it is not working.

Any help would be appreciated.

(Note:It would be better to trigger the click event from the href=#1647278006925-e8321147-313b )

*I can not edit the html.

**I can edit, add or remove classes or ids in the iframe.

Topic footer scripts iframe jquery Wordpress javascript

Category Web


Did you inspect your code for any errors?

If the error is "Uncaught TypeError: $ is not a function", then maybe you can add the code as below.

<script>
jQuery(document).ready(function($) {
    //your code starts here
    <iframe id="myiFrame" class="stop-lazy" data-src="https://some.iframe" frameborder="0" allowtransparency="true" style="width: 100%;min-height: 150px;"></iframe>
});
</script>

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.