Как удалить код из строки HTML? - PullRequest
1 голос
/ 21 апреля 2010

У меня есть переменная, которая имеет эту строку:

<DIV><SPAN style="FONT-FAMILY: Tahoma; FONT-SIZE: 10pt">[If the confirmation is active the subscriber will receive this email after succesfully confirming. If not, this will be the first and only email he will receive.]</SPAN></DIV>
<p align=center>
    <input class=fieldbox10 type = 'button' name = 'button' value = 'Close' onclick = "window.close()">
</p>

Как удалить приведенную ниже строку, не беспокоясь о пробелах через Javascript (или jQuery)?

<p align=center>
    <input class=fieldbox10 type = 'button' name = 'button' value = 'Close' onclick = "window.close()">
</p>

Ответы [ 2 ]

4 голосов
/ 21 апреля 2010

Может быть, это?

$(html).remove('p');
2 голосов
/ 21 апреля 2010

Если ваш var был myString, вы можете сделать это:

var temp = $("<div />").append(myString);
temp.find('p:has(input[value=Close])').remove('p');
myString = temp.html();​

Вы можете увидеть рабочую демонстрацию здесь

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...