setAttribute не срабатывает на действие
Почему так скрипт срабатывает:
<script> document.getElementById('shere_link').setAttribute ('data-url', 'http://site.com.ua/fav/?id=777'); </script> а так нет: <script> $(function() { $(".target").click(function(){ document.getElementById('shere_link').setAttribute ('data-url', 'http://site.com.ua/fav/?id=777'); }); }); </script> Заранее спасибо. |
Потому что обработчик события не был установлен, очевидно же.
|
Или jQuery не подключил.
|
jQuery подключил.
<script> $(function() { $(".target").click(function(){ document.getElementById('shere_link').setAttribute ('data-url', 'http://site.com.ua/fav/?id=777'); document.getElementById('shere_link').className = newClass; }); }); </script> Класс меняет, а data-url - нет. |
document.getElementById('shere_link').data('url','http://site.com.ua/fav/?id=777')а лучше $('#shere_link').data('url','http://site.com.ua/fav/?id=777') |
Цитата:
Скорей всего у меня неверный подход: Мне нужно асинхронно менять ссылку для сервиса "PLUSO" То есть, при загрузке подставляется ссылка -> потом на определенное событие - меняет ссылку. Так вот - не меняет. Возможно есть другое решение? <script type="text/javascript">(function() { if (window.pluso)if (typeof window.pluso.start == "function") return; if (window.ifpluso==undefined) { window.ifpluso = 1; var d = document, s = d.createElement('script'), g = 'getElementsByTagName'; s.type = 'text/javascript'; s.charset='UTF-8'; s.async = true; s.src = ('https:' == window.location.protocol ? 'https' : 'http') + '://share.pluso.ru/pluso-like.js'; var h=d[g]('body')[0]; h.appendChild(s); }})();</script> <div class="shareBlock"> <span class="label">Поделиться с другом:</span> <div class="share"> <div class="pluso" id="shere_link" data-background="transparent" data-options="medium,square,line,horizontal,counter,theme=04" data-services="vkontakte,odnoklassniki,facebook,twitter,google,print" data-url="http://site.com.ua/fav/[PHP]<? echo $share_link; ?>[/PHP]" data-title="Избранные модели"></div> </div> |
Часовой пояс GMT +3, время: 05:28. |