user4323888
user4323888

Reputation:

Add Id to iframe tag with JS

I need to add an ID to an iframe tag using Jquery.

Like this :

<iframe></iframe>

TO

<iframe id="something"></iframe>

Thanks for help

Upvotes: 2

Views: 13472

Answers (1)

Bhushan Kawadkar
Bhushan Kawadkar

Reputation: 28513

Try this : You can use attr() method in jquery for iframe, see below code

NOTE : - Assuming you have only one iframe element, otherwise below code will set id of every iframe in html DOM

You need to add jquery library (jquery.min.js as shown below ) and put your script inside script tag.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script>
   $(function(){
    $('iframe').attr('id','something');
  });
</script>

Upvotes: 3

Related Questions