Preserve Text Readability During Font Fallback with JavaScript

Kumar Varma
Updated on 23-Jun-2020 13:06:14

180 Views

Use the fontSizeAdjust property to preserve the readability of text. It sets the aspect value of a font i.e. the difference between the size of lowercase and uppercase letters.ExampleYou can try to run the following code to preserve the readability of text when font fallback occurs with JavaScript −Live Demo           Heading 1                This is Demo Text.             Set Aspect Value                function display() {             document.getElementById("myID").style.fontFamily = "verdana,sans-serif";             document.getElementById("myP").style.fontSizeAdjust = "0.90";          }          

Set Space Between Characters in Text with JavaScript

Samual Sam
Updated on 23-Jun-2020 13:05:42

444 Views

To set the space between characters, use the JavaScript letterSpacing property.ExampleYou can try to run the following code to set the space between characters in a text with JavaScript −Live Demo           Heading 1       This is Demo Text.       Set Space between characters                function display() {             document.getElementById("myID").style.letterSpacing = "7px";          }          

Handle addEventListener Issue in Internet Explorer with JavaScript

George John
Updated on 23-Jun-2020 13:05:00

2K+ Views

To deal with “Object doesn’t support this property or method” issue in JavaScript, while using events and Internet Explorer, update your code with this −Example                      ...     You can also use attachEvent in IE to solve this issue like this −if (ev.addEventListener) {    ev.addEventListener('click', myText, false); } else if (ev.attachEvent) {     ev.attachEvent('onclick', myText); }

Set Height Equal to Dynamic Width in CSS Fluid Layout with JavaScript

Rishi Rathor
Updated on 23-Jun-2020 13:04:18

669 Views

To set height equal to the dynamic width in JavaScript, you can try to run the following code −Example                    .wrap {             width:400px;             height:300px;             border:2px solid yellow;          }          .myChild{             width: 80%;             border:1px solid red;          }                                  var res = $('.myChild').width();          $('.myChild').css({             'height': res + 'px'          });                                        

Easiest Code for Array Intersection in JavaScript

Srinivas Gorla
Updated on 23-Jun-2020 13:03:41

126 Views

For array intersection, you can try to run the following code in JavaScript −Example                    let intersection = function(x, y) {             x = new Set(x), y = new Set(y);             return [...x].filter(k => y.has(k));          };          document.write(intersection([5,7,4,8], [3,9,8,4,3]));          

Set listStyleImage, listStylePosition, and listStyleType in One Declaration with JavaScript

Sharon Christine
Updated on 23-Jun-2020 13:03:09

118 Views

To set the list properties in a single declaration, use the listStyle property in JavaScript.ExampleYou can try to run the following code to set the listStylePosition and listStyleType property in one declaration with JavaScript −Live Demo                    One          Two             Change style                function display() {             document.getElementById("myID").style.listStyle = "circle outside";          }          

Set Minimum Number of Visible Lines for an Element in JavaScript

George John
Updated on 23-Jun-2020 13:02:06

152 Views

Use the orphans property in JavaScript to set the minimum number of lines for an element that must be visible at the top of a page. You can try to run the following code to learn how to implement orphans property −document.getElementById("p").style.orphansThis is how you can return the orphans property −var res = object.style.orphans;This is how to set the orphans property −object.style.orphans='number|initial|inherit'

Use JavaScript Object.defineProperty

Abhinanda Shri
Updated on 23-Jun-2020 13:01:23

259 Views

If you want to define a new or modify a property on an object, then use the Object.defineProperty in JavaScript. Use the property like the following −Object.defineProperty(obj, prop, descriptor)The following are the parameters −obj – Property is defined on this object. prop – Name of the property descriptor  − The descriptor for the propertyExampleYou can try to run the following code to learn how to implement Object.defineProperty in JavaScript −                    const obj = {};          Object.defineProperty(obj, 'prop', {             value: 20,             writable: false          });          obj.prop = 10;          document.write(obj.prop);          

Set Alignment of Items in Flexible Container Using JavaScript

Krantik Chavan
Updated on 23-Jun-2020 13:00:21

115 Views

Use the alignContent property in JavaScript to set the alignment between the items inside a flexible container.ExampleYou can try to run the following code to implement alignContent property in JavaScript −                    #box {             border: 1px solid #000000;             width: 240px;             height: 150px;             flex-flow: row wrap;             align-content: space-around;             display: flex;          }          #box div {             height: 80px;             width: 80px;          }                              DIV1          DIV2          DIV3             Set                function display() {             document.getElementById("box").style.alignContent = "space-between";          }          

Inject JavaScript in WebBrowser Control

Arjun Thakur
Updated on 23-Jun-2020 12:59:49

2K+ Views

To inject JavaScript in WebBrowser control, use the following steps − Firstly, create a Windows Forms application in Visual Studio. Now, drag a WebBrowser control to the form Set the Url property. Right-click the project, choose to Add reference... → COM → Type Libraries Select "Microsoft HTML Object Library"  Add the following code to inject JavaScript.private void myWebBrowser(object sender, WebBrowserDocumentCompletedEventArgs e){      // head element    HtmlElement hElement = weBrowser.Document.GetElementsByTagName("head")[0];    // script element    HtmlElement sElement = weBrowser.Document.CreateElement("script");    IHTMLScriptElement val = (IHTMLScriptElement)sElement.DomElement;    element.text = "function sayHello() {       alert('Weclome')    }";    hElement.AppendChild(sElement);    weBrowser.Document.InvokeScript("How you doing?"); }

Advertisements