Skip to content
Advertisement

Dynamically change attribute of html button with Javascript

I have an html button where the ‘data-item-price’ attribute needs to be dynamically set on page load. The button has to be html but I can manipulate it with Javascript.

JavaScript

Advertisement

Answer

  • Using DOM’s setAttribute() property

    JavaScript
  • Using JavaScript’s dataset property

    JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement