Мой html-код выглядит так
<a class="wsl_connect_with_provider" title="Connect with Facebook" data-provider="Facebook">
<img src="/assets/img/facebook.png">
</a>
<a class="wsl_connect_with_provider" title="Connect with Twitter" data-provider="Twitter">
<img src="/assets/img/twitter.png">
</a>
Я хотел бы заменить img
на title
используя jquery
.
<a class="wsl_connect_with_provider" title="Connect with Facebook" data-provider="Facebook">
Connect with Facebook
</a>
<a class="wsl_connect_with_provider" title="Connect with Twitter" data-provider="Twitter">
Connect with Twitter
</a>
Может ли кто-нибудь сказать мне, как это сделать?
Это должно работать:
$('a.wsl_connect_with_provider').each(function(){
$(this).text($(this).prop('title'));
});
Демо здесь
$.each($('img'), function(){
$(this).replaceWith('<span>'+$(this).attr('title')+'</span>');
});
$.each($('img'), function(){ $(this).replaceWith('<span>'+$(this).closest('a').attr('title')+'</span>'); });
$('.wsl_connect_with_provider img').each(function () {
$(this).replaceWith(
$(this.parentNode).attr('title')
);
});