创建<ins>元素,用于在加载时进行广告,不带JQuery
Creating an <ins> element for advertising at load time, without JQuery
通常,谷歌广告可以在HTML文档中声明如下:
<div id="myAds">
<ins class="adsbygoogle"
style="display:inline-block;width:160px;height:600px"
data-ad-client="ca-pub-1234567890"
data-ad-slot="0987654321">
</ins>
</div>
但是,我需要在加载页面时有条件地插入该广告元素。如何在Javascript中动态创建这样一个<ins>
元素?我正在寻找一个没有JQuery的代码示例。
显然,以下操作完成了任务:
var myAds = document.getElementById("myAds");
var frag, elem;
frag = document.createDocumentFragment();
elem = document.createElement('ins');
frag.appendChild(elem);
elem.className += "adsbygoogle";
elem.setAttribute("style", "display:inline-block;width:160px;height:600px");
elem.setAttribute("data-ad-client", "ca-pub-1234567890");
elem.setAttribute("data-ad-slot", "0987654321");
myAds.appendChild(frag);
相关文章:
- 在web应用程序中的新搜索中重新加载搜索结果(不带jQuery)
- 不带jquery的全屏分页
- ajax中的文本链接不带Jquery
- 删除不带jQuery的覆盖css
- 获取不带Jquery的嵌套父HREF节点
- 将javascript中的JSON输出为不带jquery的列表
- 等效于不带jQuery的getJSON函数
- 使用Javascript(不带jquery)触发Anchor链接上的链接
- 将数据与HTML元素关联(不带jQuery)
- 添加一个不带jquery的工具提示-Javascript
- 将类添加到指令中的元素,带有角度和不带 jquery
- 通过不带 jquery 的索引选择一个元素
- 输出脚本标签而不带jQuery,避免执行
- 使用 javascript 在标签中应用样式(不带 jQuery)
- 将AJAX响应加载到浏览器中(不带jQuery)
- css第n个child第n个last类型,带javascript–不带jquery
- 不带jQuery的html日期选择器中的OnClick事件
- 创建<ins>元素,用于在加载时进行广告,不带JQuery
- 检查不带JQuery的select元素中是否存在选项
- 淡入淡出,不带jQuery