Posts

Showing posts with the label Javascript Example

Change Styles With Jquery Code Example

Example 1: jquery add style //revising Ankur's answer //Syntax: $ ( selector ) . css ( { property - name : property - value } ) ; //Example: $ ( '.bodytext' ) . css ( { 'color' : 'red' } ) ; Example 2: jquery modify style attribute $ ( '#yourElement' ) . css ( 'display' , 'none' ) ; Example 3: set css using jquery $ ( '.name' ) . css ( 'color' : 'blue' ) ;

Clear Input Value Jquery Code Example

Example 1: clear input jqueyr $ ( '#inputButtonID' ) . val ( '' ) ; Example 2: jquery clear form values $ ( ".reset" ) . click ( function ( ) { $ ( this ) . closest ( 'form' ) . find ( "input[type=text], textarea" ) . val ( "" ) ; } ) ; Example 3: clear input field jquery $ ( '#shares' ) . val ( '' ) ; Example 4: how To clear all the input element inside div using jquery By LOVE $ ( '#divStaffContent' ) . find ( 'input:text, input:password, select' ) . each ( function ( ) { $ ( this ) . val ( '' ) ; } ) ; } Example 5: empty the value of an input in jquery $ ( '#field' ) . val ( '' ) ; Example 6: clear value input jquery < body > < form method = "" action = "" > < input type = "text" name = "email" cl...

Button Data Attribute Jquery Code Example

Example 1: jquery get data attribute value /* html */ < a data - id = "123" > link < / a > /* js */ $ ( this ) . attr ( "data-id" ) // returns string "123" $ ( this ) . data ( "id" ) // returns number 123 (jQuery >= 1.4.3 only) Example 2: javascript get data-id attribute //get data-id attribute in plain Javascript var element = document . getElementById ( 'myDivID' ) ; var dataID = element . getAttribute ( 'data-id' ) ; //get data-id using jQuery var dataID = $ ( 'myDivID' ) . data ( 'data-id' ) ; Example 3: jquery get data attribute < a data - id = "123" > link < / a > var id = $ ( this ) . data ( "id" ) ; // Will set id to 123 Example 4: jquery data attribute data attribute in jquery For setting attribute data to the element Html < p id = "assign" > Assigning data attribute < / p > jquery $ ( "#assi...

AutoCapitalize Text Input React Native Code Example

Example 1: react native textinput import React , { Component } from 'react' ; import { TextInput } from 'react-native' ; export default function UselessTextInput ( ) { const [ textInputValue , setTextInputValue ] = React . useState ( '' ) ; return ( < TextInput style = { { height : 40 , borderColor : 'gray' , borderWidth : 1 , placeholderTextColor : 'gray' , } } onChangeText = { text => setTextInputValue ( text ) } value = { textInputValue } placeholder = "Insert your text!" / > ) ; } Example 2: react native input import React , { Component } from 'react' ; import { TextInput } from 'react-native' ; export default function UselessTextInput ( ) { const [ value , onChangeText ] = React . useState ( 'Useless Placeholder' ) ; return ( < TextInput style ...

Button Disable Jquery Code Example

Example 1: jquery add disabled to button $ ( "#button" ) . attr ( "disabled" , true ) ; Example 2: How disable button jquery $ ( "button" ) . prop ( "disabled" , true ) ; Example 3: jquery enable submit button //jQuery 1.6+ use: $ ( "#submitButtonID" ) . prop ( 'disabled' , true ) ; //disable $ ( "#submitButtonID" ) . prop ( 'disabled' , false ) ; //enable //jQuery 1.5 and below use: $ ( "#submitButtonID" ) . attr ( 'disabled' , 'disabled' ) ; //disable $ ( "#submitButtonID" ) . removeAttr ( 'disabled' ) ; //enable

Char Code From Number Js Code Example

Example 1: character to ascii javascript "ABC" . charCodeAt ( 0 ) // returns 65 Example 2: how to return character associated to character code javascript console . log ( String . fromCharCode ( 65 ) ) ; // expected output: "A" Example 3: js ASCII value { "31" : "" , "32" : " " , "33" : "!" , "34" : "\"" , "35" : "#" , "36" : "$" , "37" : "%" , "38" : "&" , "39" : "'" , "40" : "(" , "41" : ")" , "42" : "*" , "43" : "+" , "44" : "," , "45" : "-" , "46" : "." , "47" : "/" , "48" : "0" , ...

Can Equals Vs Equals Java Code Example

Example: java == vs equals In general both equals ( ) and == operator in Java are used to compare objects to check equality but here are some of the differences between the two : 1 ) . equals ( ) and == is that one is a method and other is operator . 2 ) We can use == operator for reference comparison ( address comparison ) and . equals ( ) method for content comparison . - > == checks if both objects point to the same memory location - > . equals ( ) evaluates to the comparison of values in the objects . 3 ) If a class does not override the equals method , then by default it uses equals ( Object o ) method of the closest parent class that has overridden this method . // Java program to understand // the concept of == operator public class Test { public static void main ( String [ ] args ) { String s1 = new String ( "HELLO" ) ; String s2 = new String ( "HELLO...

Change Img Src From Javascript Code Example

Example 1: javascript change image src //change image src document . getElementById ( 'myImageID' ) . src = "images/my_other_image.png" ; Example 2: set img src using javascript document . getElementById ( "imageid" ) . src = "../template/save.png" ; Example 3: javascript set image src // Pure JavaScript to Create img tag and add attributes manually , var image = document . createElement ( "img" ) ; var imageParent = document . getElementById ( "body" ) ; image . id = "id" ; image . className = "class" ; image . src = searchPic . src ; // image.src = "IMAGE URL/PATH" imageParent . appendChild ( image ) ; // Set src in pic1 document [ "#pic1" ] . src = searchPic . src ; // or with getElementById document . getElementById ( "pic1" ) . src = searchPic . src ; // jQuery to archive this, $ ( "#pic1" ) . attr ( "src"...

Check String Contains Substring Javascript Code Example

Example 1: js string contais const string = "foo" ; const substring = "oo" ; console . log ( string . includes ( substring ) ) ; Example 2: js check if string contains character if ( your_string . indexOf ( 'hello' ) > - 1 ) { alert ( "hello found inside your_string" ) ; }

Bootstrap Range Slider Min Max Code Example

Example 1: price range slider bootstrap 4 < input type = "range" name = "range" step = "50000" min = "100000" max = "1000000" value = "" onchange = "rangePrimary.value=value" > < input type = "text" id = "rangePrimary" / > Example 2: bootstrap 3 min max price range slider < ! doctype html > < html lang = "en" > < head > < meta charset = "utf-8" > < meta name = "viewport" content = "width=device-width, initial-scale=1" > < title > jQuery UI Slider - Range slider < / title > < link rel = "stylesheet" href = "//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css" > < link rel = "stylesheet" href = "/resources/demos/style.css" > < script src = "https://code.jquery.com/jquery-1.12.4.js" > < / script...

BackgroundImage: `url("${src}") Code Example

Example 1: how to set background image for button in css div#submitForm input { background : url ( "../images/buttonbg.png" ) no - repeat scroll 0 0 transparent ; color : # 000000 ; cursor : pointer ; font - weight : bold ; height : 20 px ; padding - bottom : 2 px ; width : 75 px ; } Example 2: adding background image css /* Answer to: "adding background image css" */ /* The background-image property sets one or more background images for an element. By default, a background-image is placed at the top-left corner of an element, and repeated both vertically and horizontally. Tip: The background of an element is the total size of the element, including padding and border (but not the margin). Tip: Always set a background-color to be used if the image is unavailable. */ /* Set a background-image for the <body> element: */ body { background - image : url ( "paper.gif" ) ; background - co...

Button With Href Link Html Code Example

Example 1: href on a button < button onclick = "window.location.href='/page2'" > Continue < / button > Example 2: html button link < button > < a href = 'https://google.com' alt = 'Broken Link' > This is a button < / a > < / button > Example 3: html button with link < a href = "https://www.google.com" > < button > Go to Google < / button > < / a > Example 4: button href a . button { - webkit - appearance : button ; - moz - appearance : button ; appearance : button ; text - decoration : none ; color : initial ; }

Append Div In Div Jquery Code Example

Example 1: jquery add div element $ ( '#someParent' ) . append ( '<div>I am new here</div>' ) ; Example 2: append div to another div jquery < h2 > Greetings < / h2 > < div class = "container" > < div class = "inner" > Hello < / div > < div class = "inner" > Goodbye < / div > < / div >

Alert In Html W3 School Code Example

Example: javascript alert alert ( "string" ) ;

Button Disabled Javascript Code Example

Example 1: javascript disable button //disable the button document . getElementById ( BUTTON_ID ) . disabled = true ; //reable the button document . getElementById ( BUTTON_ID ) . removeAttribute ( 'disabled' ) ; Example 2: javascript how to disable a button //Using Javascript //Disabling a html button document . getElementById ( "Button" ) . disabled = true ; //Enabling a html button document . getElementById ( "Button" ) . disabled = false ; //Using jQuery //Disabling a html button $ ( '#Button' ) . attr ( 'disabled' , 'disabled' ) ; //Enabling a html button $ ( '#Button' ) . removeAttr ( 'disabled' ) ; Example 3: html button disabled < button type = "button" disabled > This button is disabled < / button > Example 4: javascript disable button document . getElementById ( BUTTON_ID ) . disabled = true ; Example 5: enable html button $ ( '#Button' ) ....

Android Studio Change Package Name Code Example

Example: android studio change package name In Android Studio , you can do this : For example , if you want to change com . example . app to my . awesome . game , then : In your Project pane , click on the little gear icon ( Gears icon ) Uncheck the Compact Empty Middle Packages option Compact Empty Middle Packages Your package directory will now be broken up into individual directories Individually select each directory you want to rename , and : Right - click it Select Refactor Click on Rename In the pop - up dialog , click on Rename Package instead of Rename Directory Enter the new name and hit Refactor Click Do Refactor in the bottom Allow a minute to let Android Studio update all changes Note : When renaming com in Android Studio , it might give a warning . In such case , select Rename All Enter image description here Now open your Gradle Build File ( build . gradle - Usually app or mobile ...

Add Multiple Class To Html Element Code Example

Example 1: css assign multiple classes to one element To specify multiple classes , separate the class names with a space , e . g . < span class = "classA classB" > . This allows you to combine several CSS classes for one HTML element . Example 2: multiple classes in element html < article class = "column wrapper" >

Clear Canvas Javascript Html5 Code Example

Example 1: Javascript clear canvas var canvas = document . getElementById ( "myCanvasID" ) ; var context = canvas . getContext ( '2d' ) ; context . clearRect ( 0 , 0 , canvas . width , canvas . height ) ; //clear html5 canvas Example 2: resetting canvas html var canvas = document . getElementById ( 'myCanvas' ) ; var context = canvas . getContext ( '2d' ) ; context . clearRect ( 0 , 0 , canvas . width , canvas . height ) ;

Array Pop Push Javascript Code Example

Example 1: how to push items in array in javascript let items = [ 1 , 2 , 3 ] items . push ( 4 ) ; // items = [1, 2, 3, 4] Example 2: javascript pop var cars = [ 'mazda' , 'honda' , 'tesla' ] ; var telsa = cars . pop ( ) ; //cars is now just mazda,honda

Add Elements Into Array List Java Code Example

Example: how to add to an arraylist java import java . util . ArrayList ; public class Details { public static void main ( String [ ] args ) { //ArrayList<String> Declaration ArrayList < String > al = new ArrayList < String > ( ) ; //add method for String ArrayList al . add ( "Ram" ) ; al . add ( "Shyam" ) ; al . add ( "CPS" ) ; al . add ( "John" ) ; al . add ( "Steve" ) ; System . out . println ( "Elements of ArrayList of String Type: " + al ) ;