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.

Sentry blog image

How I fixed 20 seconds of lag for every user in just 20 minutes.

Our AI agent was running 10-20 seconds slower than it should, impacting both our own developers and our early adopters. See how I used Sentry Profiling to fix it in record time.

Read more

Top comments (0)

nextjs tutorial video

📺 Youtube Tutorial Series

So you built a Next.js app, but you need a clear view of the entire operation flow to be able to identify performance bottlenecks before you launch. But how do you get started? Get the essentials on tracing for Next.js from @nikolovlazar in this video series 👀

Watch the Youtube series