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"; }
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"; }
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); }
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' });
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]));
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"; }
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'
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);
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"; }
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?"); }
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP