D
D
Dimas1232017-04-27 09:07:38
JavaScript
Dimas123, 2017-04-27 09:07:38

How to dynamically change data-content value in bootstrap popover?

There is a button, when clicked, bootstrap's popover appears.

b5ec9a42107945c78330a2d13b7e9e41.png

The click counter itself and the preparation of the message I did. But I don't know

how to send this message exactly to . Button code here https://codepen.io/anon/pen/BRpdKOdata-content="Надо менять эту надпись"


<button type="button" class="btn btn-default click"
data-container="body" 
data-toggle="popover" 
data-placement="right" 
data-content="Надо менять эту надпись">
  Счетчик
</button>

<div id="output">Вот здесь выводится как надо</div>

<script>
/* Это код бутстрапа, что бы работал popover */
$(function () {
  $('[data-toggle="popover"]').popover()
})
/* Это код который я нашел и он был просто счетчик цифрами, который я модифицировал под счетчик с текстом */
$(document).ready(function() {
        var x;
        x = 0;
        $('.click').click(function() {
           
          $('#output').html(function(i, val) {
            //alert( x );
            if (x < 2) {
              return 'Один';
            } else if (x == 3) {
              return 'несколько';
            } else if (x > 3){
              return 'Много';
            }

            });
          x = x+1;	
        });
      });	

</script>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dimas123, 2017-04-28
@Dimas123

Made https://codepen.io/anon/pen/jmBqey
The code is naturally terrible, I don't know js.

F
Froggyweb, 2017-04-27
@Froggyweb

In addition to changing data-attributes, it is necessary to store information about the number of clicks on the server, otherwise everything will be reset after the page is reloaded

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question