How to select an element with its name attribute in jQuery

To select an element with its name attribute in jQuery you can use the snippet below.

Samples

Javascript Sample

if you remove the div in div[name=”de.Fesslersoft.Testname”] you will get all elements with the specific name.

You can also have a look at this JSFiddle.

If you have any questions or suggestions feel free to rate this snippet, post a comment or Contact Us via Email.

Related links:

Please rate this snippet

How to autosize UILabel to Textsize in IOS using Objective-C

labelTest.text = @"This is my Teststring.This is my Teststring.This is my Teststring.This is my Teststring.This is my Teststring.This is my Teststring.";
labelTest.numberOfLines = 0;
[labelTest sizeToFit];

Please rate this snippet

How to check if an array contains a value in Javascript

To check if an array contains a value in Javascript you can use the snippet below.

Sample Javascript

Array.prototype.inArray = function (inputValue) {
	var counter;
	for (counter=0; counter < this.length; counter++) {
		if (this[counter] === inputValue) {
			return true;
		}
	}
	return false;
};

Please rate this snippet

How to remove an element using Javascript

To remove an element using javascript, you can use one of the following snippets.

Sample Javascript

//usage document.getElementById("ElementId").remove();
Element.prototype.remove = function() {
	this.parentElement.removeChild(this);
}

Sample Javascript

//usage document.getElementsByClassName("Elements").remove();
NodeList.prototype.remove = HTMLCollection.prototype.remove = function() {
	for(var index = 0, length = this.length; index < length; index++) {
		if(this[index] && this[index].parentElement) {
			this[index].parentElement.removeChild(this[index]);
		}
	}
}

removeChild() is the only method supported by the DOM to remove a element in Javascript (see -> Mozilla MDN Node.removeChild()).

Please rate this snippet

How to remove all children from XNode in C# and VB.NET

To remove all children from XNode in C# and VB.NET you can use the following snippet.

Sample C#

public static XDocument RemoveAllChildren(XNode xNode)
{
	if (xNode.IsNull() || String.IsNullOrEmpty(xNode.ToString()))
	{
		return null;
	}
	var xElement = xNode.ToXElement();
	xElement.RemoveNodes();
	return XDocument.Parse(xElement.ToString());
}

Sample VB.NET

Public Shared Function RemoveAllChildren(xNode As XNode) As XDocument
	If xNode.IsNull() OrElse [String].IsNullOrEmpty(xNode.ToString()) Then
		Return Nothing
	End If
	Dim xElement = xNode.ToXElement()
	xElement.RemoveNodes()
	Return XDocument.Parse(xElement.ToString())
End Function

Please rate this snippet

How to remove all children from XMLNode in C# and VB.NET

To remove all children from XMLNode in C# and VB.NET you can use the follwing snippet.

Sample C#

public static XmlDocument RemoveAllChildren(XmlNode xmlNode)
{
	if (xmlNode.IsNull() || String.IsNullOrEmpty(xmlNode.ToString()))
	{
		return null;
	}
	while (xmlNode.HasChildNodes)
	{
		xmlNode.RemoveChild(xmlNode.FirstChild);
	}
	return xmlNode.OuterXml.ToXmlDocument();
}

Sample VB.NET

Public Shared Function RemoveAllChildren(xmlNode As XmlNode) As XmlDocument
	If xmlNode.IsNull() OrElse [String].IsNullOrEmpty(xmlNode.ToString()) Then
		Return Nothing
	End If
	While xmlNode.HasChildNodes
		xmlNode.RemoveChild(xmlNode.FirstChild)
	End While
	Return xmlNode.OuterXml.ToXmlDocument()
End Function

Please rate this snippet