根据iframe内容向父页面中的元素添加类

时间:2018-08-13 19:13:43

标签: javascript html class iframe

我的页面上有许多锚点,这些锚点用作将内容加载到页面上iframe的按钮。如果内容是从父级外部加载到iframe中的,那么我想向父级页面上的相关锚点添加一个类,以显示iframe中正在显示的内容。

父页面是这样的:

<head>
<base target="iframe">
</head>
<body>
<a class="btn" href="dog.html">
<a class="btn" href="cat.html">
<a class="btn" href="bird.html">
<iframe src="blank.html" id="iframe" name="iframe"></iframe>
</body>

当其中一个子页面加载到iframe中时,我希望锚根据加载的内容突出显示,例如:

<a class="btn selected" href="dog.html">

我该怎么做?我是javascript的新手,但我相信它可以完成,因此对您有所帮助。

0 个答案:

没有答案
相关问题