jquery - Javascript handle 2 data attribute -


i need use data attribute in html <div id="userlist" data-user="a.a.m"></div> need alert data-user used

var userlist = document.getelementbyid("userlist");  var show = userlist.getattribute("data-user"); alert(show); 

my question how handle many data-user in html like

<div id="userlist" data-user="a.a.m"></div> <div id="userlist2" data-user="a.a.m2"></div> alert a.a.m , a.a.m2

thanks in advance , sorry bad english.

you know how alert 1, alert 2:

alert @ same time:

var data1 = document.getelementbyid("userlist").getattribute("data-user"); var data2 =  document.getelementbyid("userlist2").getattribute("data-user");  var data = data1 +"\n" +  data2; //"\n" can other separators  alert(data) 

if have many of them, can use jquery: add in , before other js code.

 <script src="http://code.jquery.com/jquery-2.1.1.min.js"></script> 

then :

  $("div[id^=userlist]").each(function(){       alert($(this).attr("data-user"));     }); 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -