Get Attribute Value Of Parent Element From Iframe Content June 25, 2024 Post a Comment Is there a way to get the value of attribute data-media if I'm running the script inside the iframecontent? Code looks like this: Solution 1: Well you dont really need to access the parent. As you are running the script inside iframe. iframe is currently the window for your script inside iframe. So accessing window element should give you the said attr. Try this (not tested):alert($(window).attr('data-media')); CopySolution 2: Did you tried this:window.frameElement.getAttribute("data-media"); CopySolution 3: Firstly, add an ID or CLASS to your iframe element (such as id='myframe') You can then use jquery to access any of the attributes with:var parent=window.parent.document.getElementById('#myframe'); CopyNow simply get your attribute (not tested):myAttr=$(parent).data("my-data-attribute") or myAttr=$(parent).attr("myelement") Copy Share Post a Comment for "Get Attribute Value Of Parent Element From Iframe Content"
Post a Comment for "Get Attribute Value Of Parent Element From Iframe Content"