When you click the theme button when you click

I am trying to change the theme of the button data when I click.

I call this JavaScript function in the onClick handler:

function changeNextButtonColor() { var nextButton = document.getElementById('next'); nextButton.setAttribute('data-theme', 'a'); } 

but the theme does not change. Any ideas?

+4
source share
2 answers

After you have installed the theme on the button, you need to call "update" on it, as shown below ...

 $("#next").attr("data-theme","a").button('refresh'); 

If you want to associate this type of behavior with all the β€œnext” buttons in the process, and there may be more than one, you might consider making something more like this. He will check each page for a button that has a colorChangeButton class, and then, when clicked, changes the theme to an alternative theme that is specified in this button attribute for the theme "Topic Theme".

 <a href="#" data-role="button" class="colorChangeButton" data-theme-pressed="a" data-theme="b">Next</a> <script type='text/javascript'> $('div').live('pageinit', function(){ $("a.colorChangeButton).click(function(){ var $thisButton = $(this); $thisButton.attr("data-theme",$thisButton.attr("data-theme-pressed")).button('refresh'); }); }); </script> 
+3
source
 function changeNextButtonColor() { $('#next').attr({'data-theme': 'a'}); } 

If you are using jQuery, this is your code.

+2
source

Source: https://habr.com/ru/post/1386957/


All Articles