label bien bonito con css in javascript

To label something in CSS means to add a visual marker or tag to an HTML element. Here's an example of how to add a label to an element using JavaScript:

<div id="myDiv">This div needs a label</div>
45 chars
2 lines
/* define the label styles */
.label {
  background-color: yellow;
  color: black;
  font-size: 12px;
  padding: 3px;
  border: 1px solid #000;
}

/* add the class to the element using JavaScript */
<script>
const myDiv = document.getElementById('myDiv');
const label = document.createElement('span');
label.innerText = 'label';
label.classList.add('label');
myDiv.appendChild(label);
</script>
395 chars
18 lines

In this example, we define a label class in CSS with a yellow background and black text. We then use JavaScript to find the myDiv element, create a new span element with the label text and add the label class to it. Finally, we append the new span element to the end of myDiv element.

related categories

gistlibby LogSnag