我正在尝试将类添加到嵌入元素中,如下所示:
$(".single-floorplan embed#2").addClass("activeFloorplan");
然而这不起作用,班级没有添加,我甚至尝试过
$(".single-floorplan #2").addClass("activeFloorplan");
仍然没有,没有课程被添加。
这是嵌入对象。
<embed src="~/PDFs/floorplans/pdf.pdf" height="500" type='application/pdf' id="2">
如何将类添加到embed元素。
embed元素包含在一个名为single-floorplan的类中。
答案 0 :(得分:2)
我猜你已经尝试了
$(".single-floorplan embed#2").addClass("activeFloorplan");
在embed object
放入文档之前
因此,请确保在放置此embed
对象后放置js代码。
答案 1 :(得分:0)
作为一个非常粗略的想法,您可以尝试以下方法:
setTimeout(function(){$(&#34; .single-floorplan#2&#34;)。addClass(&#34; activeFloorplan&#34;);},5000);
答案 2 :(得分:0)
$('#2').addClass('activeFloorplan')
如果您正在使用WordPress,CMS或其他类型的cookie切割器设置,结果将非常(非常非常)。
<强>段强>
$('#1').addClass('activeFloorplan');
$('#2').addClass('activeFloorplan');
$('#3').addClass('activeFloorplan');
body {
font: 400 12px/1.4 Verdana
}
#a2 {
border: 5px solid #0e0
}
#a3 {
border: 5px solid #e00
}
.activeFloorplan {
outline: 10px dashed #930;
}
.g {
color: green;
}
.b {
color: blue;
}
.r {
color: red;
}
div p {
font-size: 14px;
background: #fc1
}
code {
background: #05f;
color: #efe;
padding: 1px 2px;
}
.scroll {
font-size: 20px;
text-align: center;
}
.tip {
border: 2px solid tomato;
border-radius: 40%;
line-height: 3;
width:50%;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class='scroll'>▼▼▼Scroll▼▼▼</div>
<p>All nodes with the class <code>.activeFloorplan</code> have a brown dashed outline. This indicates that each time <code>.addClass()</code> was applied directly to a node's <code>id</code>, it was successful. So if there's an <code>id</code> on our target node...just
select the <code>id</code>.</p>
<p class='tip'>Use <code>$('#2').addClas('activeFloorplan')</code>
</p>
<p class='g tip'>Try an <iframe> for PDFs</p>
<p class='b'><embed> is good for SVG</p>
<p class='r'><embed> is not good for PDF</p>
<p>If the <iframe> doesn't work...check the location of said PDF.</p>
<div id='al'>
<div class='scroll'>▼▼▼Scroll▼▼▼</div>
<p>This is a PDF within an <iframe></p>
<iframe id="1" src="http://www.gtupw.org/articles/attachments/1358398740.pdf" frameborder='5' width='500'></iframe>
</div>
<div class='scroll'>▼▼▼Scroll▼▼▼</div>
<div id='a2'>
<p>This is a SVG within an <embed></p>
<embed id="2" src="https://upload.wikimedia.org/wikipedia/commons/9/99/Compass_rose_simple.svg">
</div>
<div class='scroll'>▼▼▼Scroll▼▼▼</div>
<div id='a3'>
<p>This is a PDF within an <embed></p>
<embed id="3" src="http://www.gtupw.org/articles/attachments/1358398740.pdf">
</div>
<div class='scroll'>✲✲✲END✲✲✲</div>