কম্পিউটার টিউটোরিয়াল

HTML DOM id Property

HTML DOM id প্রপার্টি একটি HTML এলিমেন্টের ID রিটার্ন করে এবং সেট করতে দেয়।

সিনট্যাক্স

ID পাওয়ার জন্য:

object.id

ID সেট করার জন্য:

object.id = "value"

এখানে value এলিমেন্টের ID নির্দেশ করে।

উদাহরণ

<!DOCTYPE html> <html> <head> <style>    p{       background-color:#347924;       color:#fff;       padding:8px;    }    .show{       margin:8px;       color:#347924;       font-size:18px;       font-weight:bold;    } </style> </head> <body> <h1>id property Example</h1> <p id="Awesome-para">This is a paragraph with some text and this para has an id "Awesome-para"</p> <button onclick="getId()">Show Id</button> <button onclick="changeId()">Change Id</button> <div class="show"></div> <script>    function getId() {       var paraId = document.querySelector('p').id;       document.querySelector(".show").innerHTML = paraId;    }    function changeId() {       document.querySelector('p').id = "ID-Changed";       document.querySelector(".show").innerHTML = 'new id is "ID-Chaged"';    } </script> </body> </html>

আউটপুট

নিচের আউটপুটটি দেখাবে:

HTML DOM id Property

"Show Id" বাটনে ক্লিক করলে সবুজ প্যারাগ্রাফের ID দেখাবে।

HTML DOM id Property

এখন "Change Id" বাটনে ক্লিক করলে সবুজ প্যারের ID "Awesome-para" থেকে "ID-Changed" এ পরিবর্তন হবে:

HTML DOM id Property

"Inspect Element"-এও যাচাই করা যাবে:

HTML DOM id Property

  1. HTML DOM Ol start প্রপার্টি

  2. HTML DOM Ol reversed প্রপার্টি

  3. HTML DOM offsetWidth প্রপার্টি

  4. HTML DOM offsetParent প্রপার্টি