Posts

Using before method in jquery

To add an html element or some text right before an html element we use   before   method of jquery. This will add the given element/text right before the element which we are targeting. < input type ="button" value =" Add Before Div " onclick =" AddBeforeDiv() " /> < div id ="myDiv" class ="myClass">     This is a div </ div > < script type ="text/javascript">     function AddBeforeDiv () {         $( "#myDiv" ).before( "<span>This is appended before div</span>" );     }; </ script >

Inserting a string within string using C#

To insert a string within a string we use Insert method . This method takes two parameters. First is start index where we want to insert. Second parameter is value which we want to insert. Return type of this method is string. Here we will insert a string at 0 index . Output is shown before and after inserting the string. string str = "like rain" ; Console .WriteLine(str); str = str.Insert(0, "I " ); Console .WriteLine(str); Output Like rain I like rain

Using after method in jquery

To add an html element or some text right after an html element we use after method of jquery. This will add the given element/text right after the element which we are targeting. < input type ="button" value =" Add After Div " onclick =" AddAfterDiv() "   /> < div id ="myDiv" class ="myClass">     This is a div </ div >   < script type ="text/javascript">     function AddAfterDiv() {         $( "#myDiv" ).after( "<This is appended after div" );     };     </ script >

Convert string to upper case and lower case

To convert a string to upper case we use ToUpper method. Return type of this method is string. To convert a string into lower case we use ToLower method. Return type of this method is string. string str = "i like rain" ; str = str.ToUpper(); Console .WriteLine(str); str = str.ToLower(); Console .WriteLine(str); Output I LIKE RAIN I like rain

Get length of a string in C#

To get length of a string we use Length property of string . This returns an integer value indicating how many characters a string contains. string str = "I like rain" ; int length = str.Length; Console .WriteLine( "Length of str is " + length); Output Length of str is 11

Using keyup in jquery

To call a method after key has been released after being pressed we can use keyup method. This method will be called after releasing the key. < input type ="text" id ="txtName" /> < script type ="text/javascript">     $( function () {         $( "#txtName" ).keyup( function () {             alert( "keyup event has fired" );         });     });     </ script >

Using change method in jquery

To call a method when value of an input element is changed we use change method. This method is only applicable to input, textarea and select elements. < input type ="text" id ="txtName" /> < script type ="text/javascript">   $( function () {         $( "#txtName" ).change( function () {             alert( "Text has changed" );         });     }); </ script >