jquery and js assign the text value of one label to another label

jquery

<div class="on"><a href="javascript:;"> project </a></div>
<div class="on2"></div>

$(function(){
		 a=$(".on").find("a").text();
		$(".on2").text(a);
		})

javascript

Note: The getElementsByClassName() method returns the collection (array) of all the elements of the specified class name in the document, which can be obtained by the node index number in the node list;

<div class="on"><a href="javascript:;" name="kk"> project </a></div>
<div class="on2"></div>
<p id="p1">这是现在的标题</p>
<p id="p2">这是标题</p>
<script>
			window.onload=function(){
			a=document.getElementById("p1").innerText;//id
			document.getElementById("p2").innerHTML=a;
			b =document.getElementsByClassName("on")[0].innerHTML;//类名
    //或者
            b =document.getElementsByTagName("a")[0].innerHTML;//标签
    //或者
            b =document.getElementsByName("kk")[0].innerHTML;//name属性

			document.getElementsByClassName("on2")[0].innerHTML=b;
			}
</script>

Expansion:

6 ways to get elements in native js

  • Get by ID (getElementById) (get an element)
  • Through the name attribute (getElementsByName) (the result obtained is an array)
  • By tag name (getElementsByTagName) (the result obtained is an array)
  • By class name (getElementsByClassName) (the result obtained is an array)
  • Get an element through the selector (querySelector) (get an element)
  • Get a set of elements through the selector (querySelectorAll) (the result obtained is an array)
 

Guess you like

Origin blog.csdn.net/baidu_39043816/article/details/108603483