0

I have this code for getting the attributes of an html element inside an iframe.

Code:

$("#frameID").contents().find("#htmlelementID").attr("myattr");

My dilemma here is i want to add a new attribute on the html element inside my iframe.

I'll truly appreciate every idea that will help me on this.

1
  • 1
    Note that adding a proprietary attribute will make the HTML invalid. You should use a data-* attribute for this purpose. Commented Oct 16, 2013 at 10:36

2 Answers 2

2

Use the setter version of .attr()

$("#frameID").contents().find("#htmlelementID").attr("newattr",  'newvalue');
Sign up to request clarification or add additional context in comments.

Comments

0

by attr

$("#frameID").contents().find("#htmlelementID").attr("attrname",  'atrvalue');

by prop

$("#frameID").contents().find("#htmlelementID").prop("attrname",  'atrvalue');

Comments

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.