javascript - How to get data value from element class? -
html code:
<input type="file" name="efile" id="efile" data-cat="electronics" style="width:100%" class="alertme"> <input type="file" name="dfile" id="dfile" data-cat="decoratives" style="width:100%" class="alertme"> <input type="file" name="kfile" id="kfile" data-cat="kitchen" style="width:100%" class=""> <input type="file" name="hdfile" id="hdfile" data-cat="home" style="width:100%" class=""> <input type="file" name="ffile" id="ffile" style="width:100%" data-cat="furnitures" class="alertme">
how can data-cat attribute value class alertme exist? , reading question. weak in english please apologize me if made grammatical or spelling mistakes.
you can try
$(document).ready(function(){ $(".alertme").each(function(){ var val = $(this).data('cat'); alert(val); }); })
<input type="file" name="efile" id="efile" data-cat="electronics" style="width:100%" class="alertme"> <input type="file" name="dfile" id="dfile" data-cat="decoratives" style="width:100%" class="alertme"> <input type="file" name="kfile" id="kfile" data-cat="kitchen" style="width:100%" class=""> <input type="file" name="hdfile" id="hdfile" data-cat="home" style="width:100%" class=""> <input type="file" name="ffile" id="ffile" style="width:100%" data-cat="furnitures" class="alertme"> <script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
Comments
Post a Comment