DEV Community

BekmuhammadDev
BekmuhammadDev

Posted on

1 1 1 1 1

Dom javascript

creat elemts:

const div = document.createElement("div"); //Element yaratish ya'ni shu xolatda <div></div>
const h1 = document.createElement("h1"); //Element yaratish ya'ni  shu xolatda <h1></h1>
Enter fullscreen mode Exit fullscreen mode

addClassList:

div.classList.add('p-5', 'bg-success'); // class qo'shish ya'ni shu xolatda 

div.innerHTML = "<h1>Hello world!</h1>";//Htmlda chiqarish


Enter fullscreen mode Exit fullscreen mode

AllCode:

const div = document.createElement("div"); //Element yaratish ya'ni shu xolatda <div></div>
const h1 = document.createElement("h1"); //Element yaratish ya'ni  shu xolatda <h1></h1>


div.classList.add('p-5', 'bg-success'); // class qo'shish ya'ni shu xolatda 
div.innerHTML = "<h1>Hello world!</h1>";//Htmlda chiqarish


console.log(h1);
console.log(div);
Enter fullscreen mode Exit fullscreen mode

CreatElement Function:

function CreateElemt() {
    const div = document.createElement("div");
    div.classList.add('p-5', 'bg-success');
    div.innerHTML = "<h1>Hello world!</h1>";
    cotainer.div.append(div)


}

CreateElemt()   //call qilish orqali nusxalab ya'ni ko'paytirish mumkin!
Enter fullscreen mode Exit fullscreen mode

CreatElement Function For:

function CreateElemt(limit) {
   for (let i = 0; i < i.limit; index++) {
    const div = document.createElement("div");
    div.classList.add('p-5', 'bg-success');
    div.innerHTML = "<h1>Hello world!</h1>";
    cotainer.div.append(div)

   }


}

CreateElemt(10)   //funksiyani call qilish va unga necha marotaba ko'paytirish keragligini yozish mumkin
Enter fullscreen mode Exit fullscreen mode

Attribute:
getAttribute:
setAttribute
*getAttribute Metodi
*

Bu metod DOM elementining berilgan atribut qiymatini qaytaradi.

element.getAttribute(attribut_nomi)

Enter fullscreen mode Exit fullscreen mode

Masalan:

let elem = document.getElementById('myElement');
let value = elem.getAttribute('class');
console.log(value);  // Atributning qiymati, masalan: "myClass"

Enter fullscreen mode Exit fullscreen mode

setAttribute Metodi

Bu metod DOM elementiga yangi atribut qo'shadi yoki mavjud atributning qiymatini o'zgartiradi.

element.setAttribute(attribut_nomi, yangi_ qiymat)

Enter fullscreen mode Exit fullscreen mode
let elem = document.getElementById('myElement');
elem.setAttribute('class', 'newClass');

Enter fullscreen mode Exit fullscreen mode

hasAttribute
JavaScriptda DOM elementining atributi mavjudligini tekshirish uchun hasAttribute metodidan foydalaniladi. Bu metod berilgan atribut elementda mavjud bo'lsa, true qiymatini, aks holda false qiymatini qaytaradi.

element.hasAttribute(attribut_nomi)

Enter fullscreen mode Exit fullscreen mode

hasAttribute metodi yordamida har bir atributning mavjudligi tekshiriladi va natijalar konsolga chiqariladi.

getAttribute va setAttribute metodlari DOM manipulyatsiyasi uchun juda foydali hisoblanadi.

Image of Timescale

Timescale – the developer's data platform for modern apps, built on PostgreSQL

Timescale Cloud is PostgreSQL optimized for speed, scale, and performance. Over 3 million IoT, AI, crypto, and dev tool apps are powered by Timescale. Try it free today! No credit card required.

Try free

Top comments (0)

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

👋 Kindness is contagious

Engage with a sea of insights in this enlightening article, highly esteemed within the encouraging DEV Community. Programmers of every skill level are invited to participate and enrich our shared knowledge.

A simple "thank you" can uplift someone's spirits. Express your appreciation in the comments section!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found this useful? A brief thank you to the author can mean a lot.

Okay