使用JQuery从变量中删除DOM文本 [英] Remove DOM text from variable with JQuery

查看:422
本文介绍了使用JQuery从变量中删除DOM文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只需删除这个名字:
我已经把它分配给一个变量。如何从DOM中删除

I need to Remove this First Name : ONLY. I have already assign it to a variable. how to remove only that from DOM.

示例:

First Name :<input type="text" name="first_name" id="firstName" value="" maxlength="100" />

var label = document.getElementById(id)['previousSibling'].nodeValue;

现在标签变量包含值名字:我需要从DOM中动态地删除它。

now the label variable contains the value First Name : I need to remove this dynamically from the DOM.

推荐答案

您可以使用 removeChild()方法,如

var node = document.getElementById('firstName')['previousSibling'],
    label = node.nodeValue;
node.parentNode.removeChild(node);

演示:小提琴

这篇关于使用JQuery从变量中删除DOM文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆