Javascript Update Attribute

Total Post:108

Points:756
 1401  View(s)
Ratings:
Rate this:

<input type="text" name="araButon" onKeyUp="return arama()" class="form-control filter" data-filter="app" id="focusedInput"/>

I want to update 'data-filter' value by javascript

I tried this code :

  1. Post:194

    Points:1396
    Re: Javascript Update Attribute

    You can use dataset or setAttribute,

    // dataset
    document.getElementById('focusedInput').dataset.filter = "test";
    // setAttribute
    document.getElementById('focusedInput').setAttribute('data-filter', 'test-1');
    <input type="text" name="araButon" onKeyUp="return arama()" class="form-control filter" data-filter="app" id="focusedInput" />

      Modified On Apr-09-2018 11:52:17 PM

Answer