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 to reduce TTFB

In the past few years in the web dev world, we’ve seen a significant push towards rendering our websites on the server. Doing so is better for SEO and performs better on low-powered devices, but one thing we had to sacrifice is TTFB.

In this article, we’ll see how we can identify what makes our TTFB high so we can fix it.

Read more

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay