getelementsbytagname

Get tagname name value javascript

谁都会走 提交于 2021-01-28 05:21:41
问题 I'm trying to get the tagname of name from the below line of code. I have to get the name from the below tagname using javascript <preference name="webviewbounce" value="false" /> i need to get webviewbounce This is what i know. document.getElementsByTagName("preference") But it doesnt give me the preference name . What i want is the tagname of name which is webviewbounce 回答1: Use document.querySelector to get the element. It will return the first matched element.Then use getAttribute to get

Change style of all elements using getElementsByTagName()

穿精又带淫゛_ 提交于 2020-07-18 14:31:09
问题 I'm fairly new to javascript and have been unable to get this code to work and I am unsure were and what I'm missing. So here is what I want it to do. I'm trying to have the script read everything and switch the visibility of the span found in the body <body> <span hidden>A</span> <span>X</span> <span hidden>B</span> <span>Y</span> <span hidden>C</span> <span>Z</span> </body> So instead of reading 'X Y Z' it will display 'A B C' The code I have so far is.. $(function() { var elems = document

JS无缝滚动

孤者浪人 提交于 2020-04-04 18:47:34
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title></title> </head> <style> *{margin:0;padding:0;} #div1 {width:712px;height:108px;margin:100px auto;} #div1 ul {position:absolute;left:0;top:0;} #div1 ul li{width:200px;height:200px;background: red;position: absolute;left:200px;top:150px;} </style> <script>//无缝滚动 window.onload= function () { var oDiv=document.getElementById('div1'); var oUl=oDiv.getElementsByTagName('ul')[0]; var aLi=oul.getElementsByTagName('li'); var speed=2; oUl.innerHTML=oUl.innerHTML+oUl.innerHTML;//4+4==8 oUl.style.width=aLi[0].offsetWidth*aLi.length+'px

How to insertBefore() element in body tag?

余生长醉 提交于 2020-02-16 18:37:30
问题 I am trying to use insertBefore in js like this: var p = document.createElement("p"); p.innerHTML = "test1"; document.body.insertBefore(p, null); var p = document.createElement("p"); p.innerHTML = "test2"; document.body.insertBefore(p, null); But that would add the last p element just before the close of the body tag, how could I use it so it will be added to the top when it opens? So the last element added will be the first element inside the body tag. I tried: document.body.insertBefore(p,

getElementsByTagName得到的对象

|▌冷眼眸甩不掉的悲伤 提交于 2020-02-15 23:55:13
今天练习使用DOM创建html元素,想通过getElementsByTagName("body")获得body对象,然后建立和新创建的元素的关系,如下图: 其实,getElementsByTagName("body")得到的是一个伪数组,需要按照数组的访问方式进行方式,但是不能调用数组的方法,若需调用,则要使用Call或Apply方法。 来源: https://www.cnblogs.com/NIFS/p/12313886.html

js简单实现表格排序

拟墨画扇 提交于 2020-01-19 17:39:18
昨天看到一篇关于表格排序的随笔,鉴于本人还只会简单的js,不会使用封装,所以自己也试了一下写这个效果。可能不太优化,原理思路是:获取行对象tr,排序tr中要比较的对象td,排序后添加回tbody。如下: 样式如下: <style> thead tr td{ cursor: pointer; } thead tr td:hover{ text-decoration: underline; } </style> 结构如下: <table> <thead> <tr> <td>姓名</td> <td>性别</td> <td id="score">成绩</td> </tr> </thead> <tbody> <tr> <td>hoho</td> <td>女</td> <td>65</td> </tr> <tr> <td>haha</td> <td>男</td> <td>73</td> </tr> <tr> <td>hehe</td> <td>女</td> <td>67</td> </tr> </tbody> </table> js代码: <script> var score=document.getElementById('score'); var tbody=document.getElementsByTagName('tbody')[0]; //获取文档下的第一个tbdoy var tr

js聊天框插入表情

随声附和 提交于 2020-01-18 08:20:38
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title></title> <style> *{margin:0;padding: 0;} ul{list-style: none;} .mcont{margin:100px 20px; height: 330px;width: 450px; position: relative;} .mcont ul{ overflow: hidden; width: 360px; position: absolute; left:0; top:-70px; display:none;} .mcont li{float:left;_display:inline; width: 32px; height: 32px; margin: 0 4px 4px 0; cursor: pointer;} </style> </head> <body> <div id="meditor" class="mcont"> <div class="mbar"><input type="button" value="图片" /></div> <div id="div" contenteditable="true" style="width:600px;height:300px;border

监听键盘上下键

本秂侑毒 提交于 2020-01-18 04:03:33
< ! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" > < html > < head > < title > keyboard control 1 < / title > < style > tr . highlight { background : # 08246 B ; color : white ; } < / style > < / head > < body > < table border = "1" width = "70%" id = "ice" > < tr > < td > < input type = 'text' > < / td > < td > < input type = 'text' > < / td > < td > < input type = 'text' > < / td > < td > < input type = 'text' > < / td > < / tr > < tr > < td > < input type = 'text' > < / td > < td > < input type = 'text' > < / td > < td > < input type = 'text' > < / td > < td > < input type =

限时抢购

陌路散爱 提交于 2020-01-11 21:40:11
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>倒计时抢购商品</title> <style> html, body, ul { margin: 0; padding: 0; } body { padding: 10px; } h1 { font-size: 14px; } ul { font-size: 0; } li { list-style: none; background: url(img/down.png) 0 0 no-repeat; width: 162px; height: 279px; display: inline-block; border-top: 1px solid #A0A0A4; position: relative; } .box { position: absolute; top: 0; left: 0; background: #fff; width: 152px; height: 269px; padding: 5px; margin: 0 2px; } #showcase li:first-child .box { margin-left: 0; } .box img { width: 100px; height: 80px; margin:

事件绑定方式对比

吃可爱长大的小学妹 提交于 2020-01-08 03:49:17
<!doctype html> <html> <head> <meta charset="utf-8" /> <tilte></tilte> <style> #odiv ul{ width: 300px; height: 500px; background-color: blueviolet; } </style> </head> <body> <input type="text" id="text" /> <input type="button" value="添加" id="btn" /> <div id="odiv"> <ul></ul> </div> <script> window.onload = function() { var obtn = document.getElementById('btn'); var otext = document.getElementById('text'); var odiv = document.getElementById('odiv'); var oul = odiv.getElementsByTagName('ul')[0]; obtn.onclick = function() { var li = document.createElement('li'); var lis= oul.getElementsByTagName(