본문 바로가기
개발/JavaScript

[JS]JS/JQUERY를 이용한 NAME, CLASS 값 가져오기

by m_.9m 2022. 5. 20.

 

https://codethief.io/ko/get-id-name-and-class-values-using-javascript-jquery/

 

  //1. By id
  var name_by_id = document.getElementById("test_id").getAttribute('name');
  var class_by_id = document.getElementById('test_id').ClassName;
  //2. By class
  var name_by_class = document.getElementsByClassName('test_class')[0].getAttribute('name');
  var class_by_class = document.getElementsByClassName('test_class')[0].id;
  //3. By name
  var id_by_name = document.getElementsByName('test_name')[0].id;
  var class_by_name = document.getElementsByName('test_name')[0].className;