There is such a piece of code:
<div class="like cbutton cbutton--effect-boris" data-id="1"> <!--<img src="/images/svg/look/like.svg" height="25">--> <svg xmlns="http://www.w3.org/2000/svg" width="25" height="25" viewBox="0 0 50 50" style="display: inline-block;vertical-align: middle;height: 25px;width: 25px;"> <path style="text-indent:0;text-align:start;line-height:normal;text-transform:none;block-progression:tb;-inkscape-font-specification:Bitstream Vera Sans" d="M 16.375 9 C 10.115452 9 5 14.056532 5 20.28125 C 5 33.048861 19.486343 39.737709 24.375 43.78125 L 25 44.3125 L 25.625 43.78125 C 30.513657 39.737709 45 33.048861 45 20.28125 C 45 14.056532 39.883642 9 33.625 9 C 30.149687 9 27.086018 10.611908 25 13.0625 C 22.914613 10.611757 19.850313 9 16.375 9 z M 16.375 11 C 19.642305 11 22.480134 12.65201 24.15625 15.15625 L 25 16.40625 L 25.84375 15.15625 C 27.52092 12.651785 30.357695 11 33.625 11 C 38.810358 11 43 15.145968 43 20.28125 C 43 31.180298 30.739443 37.287299 25 41.78125 C 19.260557 37.287299 7 31.180298 7 20.28125 C 7 15.145968 11.188548 11 16.375 11 z" color="#000" overflow="visible" enable-background="accumulate" font-family="Bitstream Vera Sans"></path></svg> <?php $data = parse_ini_file("look/likes.ini"); // Парсим INI-файл $likes = $data[1]; // Получаем количество лайков у статьи ?> <span><?=$likes?></span> </div> and such js
<script type="text/javascript"> $(document).ready(function () { $(".like").bind("click", function (event) { var that = $(this); if (get_cookie("VoiceLook"+that.attr("data-id")) != "Yes") { $.ajax({ url: "look/like.php", type: "POST", data: ("id=" + that.attr("data-id")), dataType: "text", success: function (result) { if (result) { //that.text(Number(that.text()) + 1); that.children().text(Number(that.text()) + 1); } else alert("Error"); } }); document.cookie = "VoiceLook"+that.attr("data-id")+"=Yes"; } else{ alert("Вы уже голосовали за этот проект!"); } }); }); function get_cookie(cookie_name) { var results = document.cookie.match('(^|;) ?' + cookie_name + '=([^;]*)(;|$)'); if (results) return (unescape(results[2])); else return null; } When you click on .like, we start working with it. Please tell me how in the process I should work not with .like, but with span and svg inside the class. that.children () does not help.
thisin your handler is no longer.like, there is a loss of context. Stupidly output to the console, see whatthisis equal to. As an option, you can useevent.targetand already have children watching it. - pepel_xDthat.children().get(0)- svg,that.children().get(1)- span ..... respectively,that.children().get(1).innerText- text from Span, for example. ...that.data().id- the number from the datasetdatadiv, etc. - Alexey Shimanskythat.children().get(1).innerText = '666';...... and in order not to write long strings permanently,var span = that.children().get(1);and furtherspan.innerText- take the text,span.innerText = 666;will install the text - Alexey Shimansky