0

I need to create an iframe for each input on a page, but all of them must be in different variables. So, the iframes' vars must be the inputs' names.

I tried this, but it didn't work:

$("input").each(function () {

         var name = $(this).attr("name");

name = document.createElement("iframe");name.src = "";name.name = "focus";document.body.appendChild(name);
    });


This is my original working iframe create code:

var focus = document.createElement("iframe");focus.src = "";focus.style.display = "none";focus.name = "focus";document.body.appendChild(focus);

I took the input name with attr(). I want to create an iframe according to that input name. after that for example I will be able to redirect it by INPUTNAME.src

How can I create specific iframes according to input names?

1 Answer 1

1

You're getting the name of the <input>, but then you immediately overwrite it. Also, since you're using jQuery anyway, it's easier to create elements with it:

$('input').each(function() {
  $('body').append($('<iframe/>', {
    src: "",
    name: this.name
  });
});
Sign up to request clarification or add additional context in comments.

2 Comments

i clicked but nothing happens. opera by the way.
by the way if i want to redirect this iframe what will i do in the next parts of the page? in my original code, i could do this with iframe.src. now?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.