Javascript-форум (https://javascript.ru/forum/)
-   jQuery (https://javascript.ru/forum/jquery/)
-   -   нужно найти и удалить теги <a> (https://javascript.ru/forum/jquery/63685-nuzhno-najjti-i-udalit-tegi.html)

ufaclub 22.06.2016 21:00

нужно найти и удалить теги <a>
 
есть div id="tablica"

в нем html код с ссылками

например:

<a href="/reg/live/pay.php?obj=149&amp;login=блаблабла&amp;title=1">750 000 руб.</a>


а мне нужно чтобы я по клику на кнопку

jQuery("#sobrat").click(function() {}


очищал теги <a> и чтобы оставался в итоге текст 750 000 руб.

Decode 22.06.2016 21:19

ufaclub,
<div id="table">
	<a href="/reg/live/pay.php?obj=149&amp;login=блаблабла&amp;title=1">750 000 руб.</a>
	<a href="/reg/live/pay.php?obj=149&amp;login=блаблабла&amp;title=1">750 000 руб.</a>
	<a href="/reg/live/pay.php?obj=149&amp;login=блаблабла&amp;title=1">750 000 руб.</a>
</div>

<button id="button">Button</button>

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

<script>
	$('#button').click(function() {
		var str = '';

		$('#table a').each(function() {
			str += $(this).text();
			$(this).remove();
		});

		$('#table').text(str);
	});
</script>

рони 22.06.2016 21:41

ufaclub,
<!DOCTYPE html>

<html>
<head>
  <title>Untitled</title>
  <meta charset="utf-8">
 </head>

<body>

<div id="table">
  <a href="/reg/live/pay.php?obj=149&amp;login=блаблабла&amp;title=1">750 000 руб.</a>
  <a href="/reg/live/pay.php?obj=149&amp;login=блаблабла&amp;title=1">150 000 руб.</a>
  <a href="/reg/live/pay.php?obj=149&amp;login=блаблабла&amp;title=1">650 000 руб.</a>
</div>

<button id="button">Button</button>

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

<script>
  $('#button').click(function() {
    $('#table a').replaceWith(function() {
      return this.text;
    });
  });
</script>



</body>
</html>

ufaclub 22.06.2016 23:16

Спасибо!


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