<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Sumeet Raina on Medium]]></title>
        <description><![CDATA[Stories by Sumeet Raina on Medium]]></description>
        <link>https://medium.com/@searchsumeet?source=rss-fabda3185b26------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*8sWlc2gp5vwx4xDP57dBNA.jpeg</url>
            <title>Stories by Sumeet Raina on Medium</title>
            <link>https://medium.com/@searchsumeet?source=rss-fabda3185b26------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 16:32:42 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@searchsumeet/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Mastering DOM Manipulation: Accessing and Modifying HTML Elements and Content with JavaScript]]></title>
            <link>https://medium.com/@searchsumeet/mastering-dom-manipulation-accessing-and-modifying-html-elements-and-content-with-javascript-adf1895640fd?source=rss-fabda3185b26------2</link>
            <guid isPermaLink="false">https://medium.com/p/adf1895640fd</guid>
            <category><![CDATA[css]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[webdev]]></category>
            <category><![CDATA[javascript-development]]></category>
            <category><![CDATA[front-end-development]]></category>
            <dc:creator><![CDATA[Sumeet Raina]]></dc:creator>
            <pubDate>Mon, 04 Mar 2024 14:17:00 GMT</pubDate>
            <atom:updated>2024-03-04T14:17:00.735Z</atom:updated>
            <content:encoded><![CDATA[<p>In this blog let’s dive into how to access HTML elements using JavaScript and how to retrieve content inside these elements.</p><h3>1- Accessing HTML Elements from the DOM with JavaScript:</h3><h4>getElementById</h4><ul><li><strong>How it works</strong>: Retrieves an element by its unique ID.</li><li><strong>Return Type</strong>: A single Element object.</li><li><strong>Example</strong>:</li></ul><pre>&lt;div id=&quot;example&quot;&gt;Content&lt;/div&gt;</pre><pre>var element = document.getElementById(&#39;example&#39;);</pre><ul><li><strong>Returned Value Example:</strong> &lt;div id=&quot;example&quot;&gt;Content&lt;/div&gt;</li><li><strong>Accessing Returned Value: </strong>element.textContent to get &quot;Content&quot;.</li></ul><h4>getElementsByTagName</h4><ul><li><strong>How it works: </strong>Retrieves a live HTMLCollection of elements with the specified tag name,<strong> It returns and array of HTML elements</strong>.</li><li><strong>Return Type:</strong> HTMLCollection.</li><li><strong>Example:</strong></li></ul><pre>&lt;div&gt;First&lt;/div&gt;<br>&lt;div&gt;Second&lt;/div&gt;</pre><pre>var elements = document.getElementsByTagName(&#39;div&#39;);</pre><ul><li><strong>Returned Value Example:</strong> <strong>[</strong>&lt;div&gt;First&lt;/div&gt;, &lt;div&gt;Second&lt;/div&gt;<strong>]</strong></li><li><strong>Accessing Returned Value</strong>: elements<strong>[0]</strong>.textContent to get &quot;First&quot;. elements<strong>[1]</strong>.textContent to get &quot;Second&quot;</li></ul><h4>getElementsByClassName</h4><ul><li><strong>How it works:</strong> Retrieves a live HTMLCollection of all elements that have the specified class name.</li><li><strong>Return Type:</strong> HTMLCollection.</li><li><strong>Example:</strong></li></ul><pre>&lt;div class=&quot;example&quot;&gt;First&lt;/div&gt;<br>&lt;div class=&quot;example&quot;&gt;Second&lt;/div&gt;</pre><pre>var elements = document.getElementsByClassName(&#39;example&#39;);</pre><ul><li>Returned Value Example: [&lt;div class=&quot;example&quot;&gt;First&lt;/div&gt;, &lt;div class=&quot;example&quot;&gt;Second&lt;/div&gt;]</li><li>Accessing Returned Value: elements[0].textContent to get &quot;First&quot;.</li></ul><h4>querySelector</h4><ul><li><strong>How it works:</strong> Returns the first Element within the document that matches the specified selector, or group of selectors.</li><li><strong>Return Type</strong>: A single Element object or null if no matches are found.</li><li><strong>Example:</strong></li></ul><pre>&lt;div class=&quot;example&quot;&gt;Content&lt;/div&gt;</pre><pre>var element = document.querySelector(&#39;.example&#39;);</pre><ul><li><strong>Returned Value Example</strong>: &lt;div class=&quot;example&quot;&gt;Content&lt;/div&gt;</li><li><strong>Accessing Returned Value: </strong>element.textContent to get &quot;Content&quot;.</li></ul><h4>querySelectorAll</h4><ul><li>How it works: Returns a static NodeList representing a list of the document’s elements that match the specified group of selectors.</li><li>Return Type: NodeList.</li><li>Example:</li></ul><pre>&lt;div class=&quot;example&quot;&gt;First&lt;/div&gt;<br>&lt;div class=&quot;example&quot;&gt;Second&lt;/div&gt;</pre><pre>var elements = document.querySelectorAll(&#39;.example&#39;);</pre><ul><li>Returned Value Example: [&lt;div class=&quot;example&quot;&gt;First&lt;/div&gt;, &lt;div class=&quot;example&quot;&gt;Second&lt;/div&gt;]</li><li>Accessing Returned Value: elements[0].textContent to get &quot;First&quot;.</li></ul><h3>2. Accessing Content Inside HTML Elements with JavaScript</h3><h4>innerHTML</h4><ul><li><strong>How it works</strong>: Gets or sets the HTML or XML markup contained within the element.</li><li><strong>Return Type:</strong> String.</li><li><strong>Example:</strong></li></ul><pre>&lt;div id=&quot;example&quot;&gt;Hello &lt;b&gt;World&lt;/b&gt;!&lt;/div&gt;</pre><pre>var content = document.getElementById(&#39;example&#39;).innerHTML;</pre><ul><li><strong>Returned Value Example:</strong> &quot;Hello &lt;b&gt;World&lt;/b&gt;!&quot;</li><li><strong>Accessing Returned Value:</strong> Directly via the content variable.</li></ul><h4>textContent</h4><ul><li><strong>How it works:</strong> Sets or returns the text content of the specified node and all its descendants.</li><li><strong>Return Type:</strong> String.</li><li><strong>Example:</strong></li></ul><pre>&lt;div id=&quot;example&quot;&gt;Hello &lt;b&gt;World&lt;/b&gt;!&lt;/div&gt;</pre><pre>var content = document.getElementById(&#39;example&#39;).textContent;</pre><ul><li><strong>Returned Value Example: </strong>&quot;Hello World!&quot;</li><li><strong>Accessing Returned Value:</strong> Directly via the content variable.</li></ul><h4>innerText (not recommended for consistent cross-browser results)</h4><ul><li><strong>How it works:</strong> Represents the “rendered” text content of a node and its descendants.</li><li><strong>Return Type:</strong> String.</li><li><strong>Example:</strong></li></ul><pre>&lt;div id=&quot;example&quot;&gt;Hello &lt;b&gt;World&lt;/b&gt;!&lt;/div&gt;</pre><pre>var content = document.getElementById(&#39;example&#39;).innerText;</pre><ul><li><strong>Returned Value Example:</strong> &quot;Hello World!&quot;</li><li><strong>Accessing Returned Value:</strong> Directly via the content variable.</li></ul><h4>value (for input elements)</h4><ul><li><strong>How it works:</strong> Used to get the current value of input, select, or textarea.</li><li><strong>Return Type:</strong> String.</li><li><strong>Example:</strong></li></ul><pre>&lt;input type=&quot;text&quot; id=&quot;example&quot; value=&quot;Hello World&quot;&gt;</pre><pre>var content = document.getElementById(&#39;example&#39;).value;</pre><ul><li><strong>Returned Value Example:</strong> &quot;Hello World&quot;</li><li><strong>Accessing Returned Value:</strong> Directly via the content variable.</li></ul><h3>2- Accessing and Modifying CSS with the style Property</h3><h4>How it Works:</h4><ul><li>Every DOM element has a style property, which is a live representation of the element&#39;s style attribute. Through this property, you can access or modify any CSS property of that element directly.</li><li>To access a specific style, you can use element.style.cssPropertyName, where cssPropertyName is the JavaScript-friendly name of the CSS property you want to access or modify (camelCase, not kebab-case).</li><li>To modify a style, you simply assign a new value to the property.</li></ul><h4>Example Code:</h4><p>Suppose you have the following HTML element:</p><pre>&lt;div id=&quot;example&quot; style=&quot;color: blue; font-size: 14px;&quot;&gt;This is some text!&lt;/div&gt;</pre><p>You can access and modify its CSS styles like this:</p><pre>// Select the element<br>var element = document.getElementById(&#39;example&#39;);<br><br>// Accessing CSS properties<br>console.log(element.style.color); // Outputs: blue<br>console.log(element.style.fontSize); // Outputs: 14px<br><br>// Modifying CSS properties<br>element.style.color = &#39;red&#39;;<br>element.style.fontSize = &#39;20px&#39;;<br><br>// After modification<br>console.log(element.style.color); // Outputs: red<br>console.log(element.style.fontSize); // Outputs: 20px</pre><h3>3- Adding or Removing CSS Classes</h3><p>Another way to modify the styles of an element is by adding or removing CSS classes using the classList property. This does not involve directly setting style properties but can indirectly change an element&#39;s appearance by adding or removing classes that have associated styles.</p><h4>How it Works:</h4><ul><li>The classList property provides methods like add(), remove(), and toggle() to add, remove, or toggle CSS classes on an element.</li></ul><h4>Example Code:</h4><pre>&lt;style&gt;<br>    .highlight { color: yellow; background-color: black; }<br>&lt;/style&gt;<br>&lt;div id=&quot;example&quot;&gt;This is some text!&lt;/div&gt;</pre><pre>// Select the element<br>var element = document.getElementById(&#39;example&#39;);<br><br>// Adding a class<br>element.classList.add(&#39;highlight&#39;);<br><br>// Removing a class<br>element.classList.remove(&#39;highlight&#39;);<br><br>// Toggling a class<br>element.classList.toggle(&#39;highlight&#39;); // Adds the class if it&#39;s not there, removes it if it is</pre><h3>Note:</h3><ul><li>Directly modifying styles using the style property or manipulating the classList<strong> only affects inline styles. It doesn&#39;t alter stylesheets.</strong></li><li>For complex style manipulations, especially those involving pseudo-elements or media queries, consider toggling classes or using CSS variables with JavaScript modifications.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=adf1895640fd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Differentiating innerHTML, textContent, and innerText: Practical Examples in JavaScript]]></title>
            <link>https://medium.com/@searchsumeet/differentiating-innerhtml-textcontent-and-innertext-practical-examples-in-javascript-0bc5305bb5f3?source=rss-fabda3185b26------2</link>
            <guid isPermaLink="false">https://medium.com/p/0bc5305bb5f3</guid>
            <category><![CDATA[textcontent]]></category>
            <category><![CDATA[html]]></category>
            <category><![CDATA[innertext]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[innerhtml]]></category>
            <dc:creator><![CDATA[Sumeet Raina]]></dc:creator>
            <pubDate>Fri, 16 Feb 2024 20:48:14 GMT</pubDate>
            <atom:updated>2024-02-16T20:49:09.411Z</atom:updated>
            <content:encoded><![CDATA[<p>Since I started my journey with web development with full enthusiasm, I quickly realised that there were numerous tools and concepts I frequently used, yet my understanding of them remained superficial. This realisation sparked my curiosity, and forced me to delve deeper. I decided to end my confusion for once and for all.</p><p>innerHTML, textContent, and innerText are properties used in JavaScript to get or set the content of an element, but they have different behaviors and purposes.</p><h3>innerHTML</h3><ul><li><strong>Description</strong>: Gets or sets the HTML content (inner HTML) of an element. This means that it includes all the HTML tags within the element as a string. When setting content using innerHTML, it parses the content as HTML, creating new DOM elements for any HTML structure within the string.</li><li><strong>Use Cases</strong>: Useful for when you need to include HTML markup in your content. It allows you to easily add nested elements, such as &lt;span&gt;, &lt;a&gt;, or any other HTML tags.</li><li><strong>Considerations</strong>: Because it interprets the string as HTML, it can pose a security risk if used with user-generated content without proper sanitization, potentially leading to cross-site scripting (XSS) attack</li></ul><p>How to implement:</p><pre>&lt;div id=&quot;example&quot;&gt;This is &lt;span style=&quot;display: none;&quot;&gt;hidden&lt;/span&gt; text. &lt;b&gt;Bold&lt;/b&gt; text.&lt;/div&gt;</pre><pre>const element = document.getElementById(&#39;example&#39;);<br><br>// Getting the innerHTML<br>console.log(element.innerHTML); // Outputs: This is &lt;span style=&quot;display: none;&quot;&gt;hidden&lt;/span&gt; text. &lt;b&gt;Bold&lt;/b&gt; text.<br><br>// Setting the innerHTML<br>element.innerHTML = &#39;New content with &lt;a href=&quot;#&quot;&gt;a link&lt;/a&gt;&#39;;</pre><p>This will replace the content of #example with &quot;New content with a link&quot;, where &quot;a link&quot; is an actual clickable hyperlink. (Note you can use code pen to try this code.)</p><h3>textContent</h3><ul><li><strong>Description:</strong> Gets or sets the text content of a node and its descendants. Unlike innerHTML, textContent returns only the text inside an element, stripping out all the HTML tags. When setting content using textContent, the given string is treated purely as text, so any HTML tags within it would be displayed as plain text rather than being interpreted as HTML.</li><li><strong>Use Cases</strong>: Ideal for manipulating the text within elements, especially when you want to ensure that no HTML markup is accidentally parsed and rendered. This is the safest way to programmatically change the content of an element to include input from the user.</li><li><strong>Considerations</strong>: It does not parse HTML tags or affect the element’s inner HTML structure. This makes it safer for displaying user-generated content.</li></ul><pre>const element = document.getElementById(&#39;example&#39;);<br><br>// Getting the textContent<br>console.log(element.textContent); // Outputs: This is hidden text. Bold text.<br><br>// Setting the textContent<br>element.textContent = &#39;Just plain text, no HTML &lt;span&gt;tags&lt;/span&gt; will render.&#39;;</pre><p>After setting textContent, the &lt;span&gt; tags will appear as plain text in the browser, not as HTML. The display: none; style on the span is ignored, and its text is included in the output.</p><h3>innerText</h3><ul><li><strong>Description</strong>: Similar to textContent, innerText gets or sets the visible text contained within an element, taking CSS styling into account. This means it respects CSS visibility, including display:none and visibility:hidden, and does not include text of elements styled with CSS as not visible. innerText is more performance-intensive than textContent, as it requires layout calculation to determine which elements are visually displayed.</li><li><strong>Use Cases</strong>: Useful when you need the text as it is rendered (visually) on the page, including processing to visually hide elements via CSS. It’s a good choice when you want to mimic the user’s visual experience of text on a webpage.</li><li><strong>Considerations</strong>: Because it accounts for CSS styling and not just the raw text, it can be slower than textContent for large amounts of text or complex DOM structures. It&#39;s not the best choice for simply retrieving or setting text content due to its performance implications and because it can exclude text based on CSS styling.</li></ul><pre>const element = document.getElementById(&#39;example&#39;);<br><br>// Getting the innerText<br>console.log(element.innerText); // Outputs: This is text. Bold text.<br><br>// Setting the innerText<br>element.innerText = &#39;Visible text only, &lt;span&gt;not interpreted as HTML&lt;/span&gt;.&#39;;</pre><h3>Summary of Effects</h3><ul><li>innerHTML changes allow HTML structure manipulation. Setting innerHTML parses the HTML, creating or removing elements as needed.</li><li>textContent is strictly for text manipulation, ignoring any HTML tags. It&#39;s the most straightforward way to change the text, ensuring that no HTML is parsed or rendered.</li><li>innerText provides a middle ground by focusing on &quot;visually&quot; rendered text, taking CSS styling into account when getting the property. However, like textContent, setting innerText treats input as plain text.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0bc5305bb5f3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why use Javascript when we can achieve same result with just HTML and CSS?]]></title>
            <link>https://medium.com/@searchsumeet/why-use-javascript-when-we-can-achieve-same-result-with-just-html-and-css-adfe3b61bd9d?source=rss-fabda3185b26------2</link>
            <guid isPermaLink="false">https://medium.com/p/adfe3b61bd9d</guid>
            <category><![CDATA[html]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[webdev]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[javascript-development]]></category>
            <dc:creator><![CDATA[Sumeet Raina]]></dc:creator>
            <pubDate>Mon, 12 Feb 2024 13:49:19 GMT</pubDate>
            <atom:updated>2024-02-12T13:49:19.858Z</atom:updated>
            <content:encoded><![CDATA[<p>HTML and CSS can provide the basic structure and style for a website, but JavaScript adds another layer of functionality that enhances the user experience and unlocks a wider range of possibilities. Here’s why JavaScript is essential for modern web development, even if you think you can achieve the same result with just HTML and CSS:</p><p><strong>Interactivity and Dynamics:</strong></p><ul><li><strong>Dynamic content:</strong> JavaScript allows you to update content on the page without reloading the entire page, leading to faster and smoother interactions. Think about search suggestions, live chats, or real-time data updates.</li><li><strong>User interaction:</strong> With JavaScript, you can create buttons, menus, animations, and other interactive elements that respond to user actions. This makes websites more engaging and user-friendly.</li><li><strong>Validation and forms:</strong> JavaScript helps validate user input in forms, ensuring data accuracy and preventing errors before submission.</li></ul><p><strong>Advanced Features and Applications:</strong></p><ul><li><strong>Single Page Applications (SPAs):</strong> JavaScript frameworks like React or Angular enable building complex SPAs, offering a seamless, app-like experience within a web browser.</li><li><strong>Real-time applications:</strong> JavaScript is key for building real-time features like chat applications, collaborative editing tools, and live data visualisations.</li><li><strong>Offline functionality:</strong> Some JavaScript libraries enable websites to work even without an internet connection, storing data locally and syncing later.</li></ul><p><strong>Additional Benefits:</strong></p><ul><li><strong>Cross-platform compatibility:</strong> JavaScript is supported by all major web browsers, ensuring your website functions consistently across different devices and operating systems.</li><li><strong>Large community and resources:</strong> JavaScript has a vast and active community, providing abundant learning resources, libraries, and frameworks to support your development needs.</li><li><strong>Server-side capabilities:</strong> While primarily front-end, JavaScript frameworks like Node.js allow building server-side applications, offering a full-stack development approach.</li></ul><p>While HTML and CSS are fundamental, <strong>JavaScript opens the door to a whole new level of interactivity, dynamism, and powerful applications that wouldn’t be possible without it.</strong> Even if you have a basic website with just HTML and CSS, consider adding JavaScript elements to enhance its functionality and user experience.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=adfe3b61bd9d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Decoding the Essential HTML5 Boilerplate: A Step-by-Step Explanation for Your First Webpage]]></title>
            <link>https://medium.com/@searchsumeet/decoding-the-essential-html5-boilerplate-a-step-by-step-explanation-for-your-first-webpage-d1d12fc7eef5?source=rss-fabda3185b26------2</link>
            <guid isPermaLink="false">https://medium.com/p/d1d12fc7eef5</guid>
            <category><![CDATA[html5]]></category>
            <category><![CDATA[html]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[doctype]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Sumeet Raina]]></dc:creator>
            <pubDate>Thu, 25 Jan 2024 11:13:42 GMT</pubDate>
            <atom:updated>2024-01-25T11:13:42.498Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vfJRmQLE6JbhSwRuPVhmDg.png" /></figure><p><strong>&lt;!DOCTYPE html&gt;</strong>: This is the document type declaration (often referred to as <strong>doctype</strong>). It is an instruction to the web browser about what version of HTML the page is written in. In this case, it tells the browser to render the page using standards-compliant HTML5.</p><p><strong>&lt;html&gt;</strong>: This is the root element of an HTML document. All other elements must be descendants of this element.</p><p><strong>lang=&quot;en&quot;</strong>: The <strong>lang</strong> attribute specifies the language of the document&#39;s content. In this case, &quot;en&quot; stands for English. This helps search engines and browsers to present and process the content in the correct language.</p><p><strong>&lt;head&gt;</strong>: This element contains meta-information about the document that isn&#39;t displayed on the web page itself. This includes things like CSS files, JavaScript files, meta tags, and the title of the document.</p><p><strong>&lt;meta charset=&quot;UTF-8&quot;&gt;</strong>: This <strong>meta</strong> element specifies the character encoding for the HTML document. <strong>UTF-8</strong> is a character encoding capable of encoding all possible characters (called code points) in Unicode and is the industry standard.</p><p><strong>&lt;meta name=&quot;viewport&quot;&gt;</strong>: This <strong>meta </strong>tag is used to control the layout on mobile browsers. By setting <strong>width=device-width</strong>, it tells the browser to match the screen&#39;s width in device-independent pixels. <strong>initial-scale=1.0</strong> sets the initial zoom level when the page is first loaded by the browser.</p><p><strong>&lt;title&gt;</strong>: This element specifies the title of the document, which is shown in the browser&#39;s title bar or tab. It is important for SEO and for the user&#39;s understanding of what the page is about.</p><p>The closing <strong>&lt;/head&gt;</strong> tag indicates the end of the head section.</p><p><strong>&lt;body&gt;</strong>: This element contains the content of the HTML document that is visible to the user, such as text, images, links, forms, etc.<br>Everything inside the <strong>&lt;body&gt; ... </strong><strong>&lt;/body&gt;</strong> tags would be the content that users interact with on the web page. The content you put here would be displayed in the web browser window. The provided code does not have any content between the <strong>&lt;body&gt; </strong>tags, so it would show an empty page with the title &quot;Document&quot; in the browser&#39;s title bar.</p><p>The closing <strong>&lt;/html&gt;</strong> tag indicates the end of the HTML document.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d1d12fc7eef5" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>