DOM setAttributeNode() পদ্ধতি একটি HTML নথিতে একটি নির্দিষ্ট উপাদানের সাথে তার প্যারামিটারে নির্দিষ্ট একটি বৈশিষ্ট্য সেট করে এবং একটি Attr নোড অবজেক্ট হিসাবে মানটি ফেরত দেয়।
সিনট্যাক্স
নিচের সিনট্যাক্স −
node.setAttributeNode(attributeNode);
উদাহরণ
আসুন setAttributeNode() পদ্ধতি -
এর একটি উদাহরণ দেখি<!DOCTYPE html>
<html>
<head>
<style>
html{
height:100%;
}
body{
text-align:center;
color:#fff;
background: linear-gradient(62deg, #FBAB7E 0%, #F7CE68 100%) center/cover no-repeat;
height:100%;
}
.btn{
background:#0197F6;
border:none;
height:2rem;
border-radius:2px;
width:35%;
margin:2rem auto;
display:block;
color:#fff;
outline:none;
cursor:pointer;
}
</style>
</head>
<body>
<h1>DOM setAttributeNode() method Demo</h1>
<p>Hi! I'm a para element in HTML with some random text</p>
<button onclick="set()" class="btn">Set Attribute</button>
<script>
function set() {
var p=document.querySelector("p");
var attr=document.createAttribute("style");
attr.value="color:#db133a;font-size:1.2rem;";
p.setAttributeNode(attr);
}
</script>
</body>
</html> আউটপুট
এটি নিম্নলিখিত আউটপুট −
তৈরি করবে

“সেট অ্যাট্রিবিউট-এ ক্লিক করুন
এলিমেন্টে স্টাইল অ্যাট্রিবিউট সেট করতে ” বোতাম।
