Change the target of an element with jQuery

3

How can I pass this code in JavaScript to jQuery ? I did not understand the context ...

document.getElementById("imageForm").target = "my_iframe";

    
asked by anonymous 13.12.2014 / 17:07

1 answer

4

No need to change that for jQuery. Of course it can change but remember that jQuery is JavaScript and will only cause the same code to be run at the end. In other words, jQuery will run exactly that code at the end, but going through more code before and slowing down. If it is not necessary do not use jQuery.

The context here is in case you have an iFrame on the page wanting an anchor to open in that iframe instead of opening on the same page. The value you give target must match the name property of the iFrame.

If you want to do this in jQuery, you can do this:

$('#imageForm').attr('target', 'my_iframe');

Context example:

document.getElementById("minha_iframe").target = "minha_iframe";
<iframe src="" id="minha_iframe" name="minha_iframe"></iframe>
<a href="http://cnn.com" target="minha_iframe">Abrir o link na iFrame</a>
    
13.12.2014 / 17:10