javascript - Trouble capturing data attribute -


I have a bulleted list and each list item has a data attribute for the country. I get the data attribute of active list item And I want to do stuff with it. For now, I'm just trying to alert it back in a message. However, I get the warning message [object object]

Here is the HTML list:

   

This is Javascript so far:

  $ (document) .ready (function ($) {$ ("li.country_name") (" Active "); $ (this) .addClass (" active "); var cc = $ (". Active "). Data (" country "); Var country message = $ (" your country is "+ cc +"! "); Alert (Country Message);});});  

I am very new to javascript and jquery and it is trying to solve most days, but nothing is working. Can anyone help me point in the right direction?

I have modified my code now. Please also check the comment: D

  $ (function () {// This function will be executed when the document first. Var $ li = $ ("li.country_name"). Function () {$ Li.removeClass ("active") // You can cache all the items, it is not necessary that every time var cc = $ (this) .addClass ("active"). Data ("country" ); ("Your country is" + cc + "!");});});  

Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -