Javascript-форум (https://javascript.ru/forum/)
-   Общие вопросы Javascript (https://javascript.ru/forum/misc/)
-   -   replace <a href="..."> на <span> (https://javascript.ru/forum/misc/42608-replace-href%3D-na-span.html)

Luckas147 02.11.2013 22:11

replace <a href="..."> на <span>
 
Требуется для всех элементов li class="current_page_item" сделать replace тега <a href="...">Link Text</a> на <span>Link Text</span> сохранив естественно междутеговый текст

Luckas147 02.11.2013 22:28

$('.current_page_item').each(function(){
$(this).html( $(this).find('a').text() );
});


пробывал это не робит

monolithed 02.11.2013 22:38

$('.current_page_item').each(function () {
   $(this).replaceWith('<span>' + $(this).html() + '</span>');
});


Только к чему этот идиотизм?

Luckas147 02.11.2013 22:47

Цитата:

Сообщение от monolithed (Сообщение 279236)
$('.current_page_item').each(function () {
   $(this).replaceWith('<span>' + $(this).html() + '</span>');
});


Только к чему этот идиотизм?

этот код тоже пробывал - тоже не робит

monolithed 02.11.2013 23:41

Цитата:

Сообщение от Luckas147
этот код тоже пробывал - тоже не робит

Может вы не умеете им пользоваться?

<script src="http://code.jquery.com/jquery-git2.js"></script>

<ul>
    <li class="current_page_item"><a>item1</a></li>
    <li class="current_page_item"><a>item2</a></li>
    <li class="current_page_item"><a>item3</a></li>
    <li class="current_page_item"><a>item4</a></li>
    <li class="current_page_item"><a>item5</a></li>
</ul>

<script>
$('.current_page_item a').each(function () {
   $(this).replaceWith('<span>' + $(this).text() + '</span>');
});
</script>

danik.js 03.11.2013 06:49

monolithed, а что за версия jquery-git2 - это что?

ksa 03.11.2013 11:49

Цитата:

Сообщение от monolithed
$(this).replaceWith('<span>' + $(this).html() + '</span>');

Цитата:

Сообщение от monolithed
Может вы не умеете им пользоваться?
$(this).replaceWith('<span>' + $(this).text() + '</span>');

Айя-яй... :D


Часовой пояс GMT +3, время: 04:55.