Method Tavsif document.getElementById(id)
Element identifikatori bo'yicha elementni
toping
document.getElementsByTagName(name)
Teg nomi bo'yicha elementlarni toping
document.getElementsByClassName(name) Elementlarni sinf nomi bilan toping
HTML elementlarini o'zgartirish Property Tavsif element.innerHTML = new html content Elementning ichki HTML-ni o'zgartiring
element.attribute = new value
HTML elementining atribut qiymatini o'zgartiring
element.style.property = new style
HTML elementining uslubini o'zgartiring
Method Tavsif element.setAttribute(attribute, value)
HTML elementining atribut qiymatini o'zgartiring
Elementlarni qo'shish va o'chirish Method Tavsif document.createElement(element) HTML elementini yarating
document.removeChild(element)
HTML elementini olib tashlang
document.appendChild(element)
HTML elementini qo'shing
document.replaceChild(new, old)
HTML elementini almashtiring
document.write(text)
HTML chiqish oqimiga yozing
HTML tarkibini o'zgartirish HTML elementi tarkibini o'zgartirishning eng oson yo'li innerHTMLxususiyatdan
foydalanishdir. HTML elementining mazmunini o'zgartirish uchun ushbu sintaksisdan
foydalaning:
document.getElementById(id).innerHTML = new HTML Ushbu misol
elementning mazmunini o'zgartiradi:
Misol tushuntirildi:
Yuqoridagi HTML hujjatida
element mavjudid="p1"
Elementni olish uchun biz HTML DOM dan foydalanamizid="p1"
JavaScript ushbu elementning mazmunini ( innerHTML) "Yangi matn!" ga
o'zgartiradi.
Atribut qiymatini o'zgartirish HTML atributining qiymatini o'zgartirish uchun ushbu sintaksisdan foydalaning: