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 get the Month name of a Datetime in C# and VB.NET

To get the Month name of a Datetime in C# and VB.NET you can use the following snippet.

Sample C#

Console.WriteLine(new DateTime(2010, 1, 1).ToString("MMM", CultureInfo.InvariantCulture)); //Jan
Console.WriteLine(new DateTime(2010, 1, 1).ToString("MMMM", CultureInfo.InvariantCulture)); //January

Sample VB.NET

Console.WriteLine(New DateTime(2010, 1, 1).ToString("MMM", CultureInfo.InvariantCulture))
'Jan
Console.WriteLine(New DateTime(2010, 1, 1).ToString("MMMM", CultureInfo.InvariantCulture))
'January

Please rate this snippet

How to get the name of the calling method in C# and VB.NET

To get the name of the calling method in C# and VB.NET you can use the snippet below.

Sample C#

public static string GetCallingMethodName()
{
	var stackTrace = new StackTrace();
	return stackTrace.GetFrame(1).GetMethod().Name;
}

Sample VB.NET

Public Shared Function GetCallingMethodName() As String
	Dim stackTrace = New StackTrace()
	Return stackTrace.GetFrame(1).GetMethod().Name
End Function

Please rate this snippet

How to get all column names of a Table in Oracle

To get all column names of a Table in Oracle you can use the following snippet.

SELECT table_name, column_name, data_type, data_length
FROM USER_TAB_COLUMNS
WHERE table_name = 'TABLENAME'

If you are using MSSQL, take a look at this snippet -> How to list all columns from a table in MSSQL

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 get Windows Product Name in C# and VB.NET

To get Windows Product Name in C# and VB.NET you can use the following snippet.

Sample C#

public static string GetWindowsProdutName()
{
	var name = (new ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem").Get().OfType<ManagementObject>().Select(x => x.GetPropertyValue("Caption"))).First();
	return name != null ? name.ToString() : "Unknown";
}

Sample VB.NET

Public Shared Function GetWindowsProdutName() As String
	Dim name = (New ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem").[Get]().OfType(Of ManagementObject)().[Select](Function(x) x.GetPropertyValue("Caption"))).First()
	Return If(name IsNot Nothing, name.ToString(), "Unknown")
End Function

Tipp: To use ManagementObjectSearcher you need to set a Reference to System.Management.

Please rate this snippet

How to change default Admin Username in WordPress

Every default WordPress installation will create an account with a default Admin username. This can be a security issue.
To change default Admin Username in WordPress you can use the mySql snippet below.

UPDATE wp_users SET user_login = 'NewUsername' WHERE user_login = 'Admin';

Please rate this snippet

How to Remove Illegal Filename Characters in C# and VB.NET

To Remove Illegal Filename Characters in C# and VB.NET you can use the following snippet.

Sample C#

public static string RemoveIllegalFileNameChars(string input, string replacement="")
{
	var regexSearch = new string(Path.GetInvalidFileNameChars()) + new string(Path.GetInvalidPathChars());
	var r = new Regex(string.Format("[{0}]", Regex.Escape(regexSearch)));
	return r.Replace(input, replacement);
}

Sample VB.NET

Public Shared Function RemoveIllegalFileNameChars(input As String, Optional replacement As String = "") As String
	Dim regexSearch = New String(Path.GetInvalidFileNameChars()) & New String(Path.GetInvalidPathChars())
	Dim r = New Regex(String.Format("[{0}]", Regex.Escape(regexSearch)))
	Return r.Replace(input, replacement)
End Function

Please rate this snippet

How to check if a printer exists in C# and VB.NET

To check if a printer exists in C# and VB.NET you can use the following snippet.

Sample C#

public static bool PrinterExists(string printerName)
{
	if (String.IsNullOrEmpty(printerName)) {  throw new ArgumentNullException("printerName");}
	return PrinterSettings.InstalledPrinters.Cast<string>().Any(name => printerName.ToUpper().Trim() == name.ToUpper().Trim());
}

Sample VB.NET

Public Shared Function PrinterExists(printerName As String) As Boolean
	If String.IsNullOrEmpty(printerName) Then
		Throw New ArgumentNullException("printerName")
	End If
	Return PrinterSettings.InstalledPrinters.Cast(Of String)().Any(Function(name) printerName.ToUpper().Trim() = name.ToUpper().Trim())
End Function

Please rate this snippet

How to get the executable filename in C# and VB.NET

To get the executable filename in C# and VB.NET you can use one the following methods.

Sample C#

//prefered way to retrieve exe filename
Console.WriteLine(Path.GetFileName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName));
 

Console.WriteLine(AppDomain.CurrentDomain.FriendlyName); //can cause problems when using click once, also this property does not always returns the right result.

Console.WriteLine(Path.GetFileName(Assembly.GetExecutingAssembly().Location)); //can fail when used in wcf application.
Console.WriteLine(Path.GetFileName(Assembly.GetExecutingAssembly().CodeBase)); //better if shadow copy feature is active, but can fail when used in wcf application
Console.WriteLine(Path.GetFileName(Assembly.GetEntryAssembly().Location));

Sample VB.NET

'prefered way to retrieve exe filename
Console.WriteLine(Path.GetFileName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName))


Console.WriteLine(AppDomain.CurrentDomain.FriendlyName)
'can cause problems when using click once, also this property does not always returns the right result.
Console.WriteLine(Path.GetFileName(Assembly.GetExecutingAssembly().Location))
'can fail when used in wcf application.
Console.WriteLine(Path.GetFileName(Assembly.GetExecutingAssembly().CodeBase))
'better if shadow copy feature is active, but can fail when used in wcf application
Console.WriteLine(Path.GetFileName(Assembly.GetEntryAssembly().Location))

Please rate this snippet