ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Add Underline and Bold to current clicked element in JavaScript<p>Hi <a class="username" rel="Richa"> Richa</a>,</p> <p>Please refer below sample.</p> <p><span style="text-decoration: underline;"><strong>HTML</strong></span></p> <pre class="brush: html">&lt;html xmlns=&#34;http://www.w3.org/1999/xhtml&#34;&gt; &lt;head runat=&#34;server&#34;&gt; &lt;title&gt;&lt;/title&gt; &lt;style type=&#34;text/css&#34;&gt; .mystyle { color: black; font-weight: bold; text-decoration: underline; } &lt;/style&gt; &lt;script type=&#34;text/javascript&#34; src=&#34;http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js&#34;&gt;&lt;/script&gt; &lt;script type=&#34;text/javascript&#34;&gt; function showSubProcess(projid, curProcessId, processId, processCompleted, pID) { if (projid != 1) { $(&#39;#loadingmessage&#39;).show(); var elements = $(&#39;[id*=divps_subProD]&#39;); var element1 = document.getElementById(&#34;ContentPlaceHolder1_&#34; + pID); for (var i = 0; i &lt; elements.length; i++) { if (elements[i].id == element1.id) { //code to underline and bold selected text element1.className = &#34;mystyle&#34;; globalProcessId = processId; var contPalaceH = &#34;ContentPlaceHolder1_divgrgridContent_subProD_&#34; + processId; var data = document.getElementById(contPalaceH); var href = window.location.href.split(&#39;/&#39;); var root = href[0] + &#39;//&#39; + href[2] + &#39;/&#39; + href[3]; } else { //code to remove underline and bold from others elements[i].className = &#34;&#34;; } } } } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;form id=&#34;form1&#34; runat=&#34;server&#34;&gt; &lt;div id=&#34;divgrgridContent&#34; runat=&#34;server&#34;&gt; &lt;p id=&#34;ContentPlaceHolder1_divps_subProD__1_0&#34; style=&#34;cursor: pointer;&#34; onclick=&#34;showSubProcess(&#39;f01d668d-9c9d-4907-bd66-128c21c4c32d&#39;,&#39;FEL1-MCM&#39;,&#39;1&#39;,&#39;yes&#39;, &#39;divps_subProD__1_0&#39;);&#34;&gt; PROJECT1 &lt;/p&gt; &lt;p id=&#34;ContentPlaceHolder1_divps_subProD__2_0&#34; style=&#34;cursor: pointer;&#34; onclick=&#34;showSubProcess(&#39;f01d668d-9c9d-4907-bd66-128c21c4c32d&#39;,&#39;FEL1-MCM&#39;,&#39;1&#39;,&#39;yes&#39;, &#39;divps_subProD__2_0&#39;);&#34;&gt; Project2 &lt;/p&gt; &lt;/div&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt;</pre> <p><span style="text-decoration: underline;"><strong>Namespaces</strong></span></p> <p><strong>C#</strong></p> <pre class="brush: csharp">using System.Text; using System.Data;</pre> <p><span style="text-decoration: underline;"><strong>Code</strong></span></p> <p><strong>C#</strong></p> <pre class="brush: csharp">protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { string controlName = &#34;a&#34;; string divcnt = &#34;aaaa&#34;; string intSubProcess = &#34;y&#34;; string currentProcesCode = &#34;123&#34;; string strvarUrl = &#34;&#34;; int projectId = 0; DataTable dt = new DataTable(); dt.Columns.AddRange(new DataColumn[] { new DataColumn(&#34;PROCESS_STATUS&#34;, typeof(string)), new DataColumn(&#34;PROCESS_CODE&#34;, typeof(string)), new DataColumn(&#34;PROCESS_NAME&#34;, typeof(string))}); dt.Rows.Add(&#34;NEW&#34;, &#34;0&#34;, &#34;aspforums.net&#34;); //some code HtmlGenericControl divp = new HtmlGenericControl(&#34;p&#34;); divp.ID = &#34;divps_&#34; + controlName + &#34;_&#34; + divcnt + &#34;_&#34; + intSubProcess; divp.Style.Add(&#34;cursor&#34;, &#34;pointer&#34;); ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), &#34;showSubProcess&#34;, &#34;showSubProcess(1,1,1,1)&#34;, true); string processCompleted = &#34;yes&#34;; if (dt.Rows[0][&#34;PROCESS_STATUS&#34;].ToString() == &#34;0&#34; &amp;&amp; currentProcesCode == (dt.Rows[0][&#34;PROCESS_CODE&#34;].ToString())) processCompleted = &#34;no&#34;; divp.Attributes.Add(&#34;onclick&#34;, &#34;showSubProcess(&#39;&#34; + projectId + &#34;&#39;,&#39;&#34; + dt.Rows[0][&#34;PROCESS_CODE&#34;].ToString() + &#34;&#39;,&#39;&#34; + divcnt.ToString() + &#34;&#39;,&#39;&#34; + processCompleted + &#34;&#39;, &#39;&#34; + divp.ID + &#34;&#39;);&#34;); HtmlGenericControl divm = new HtmlGenericControl(&#34;i&#34;); divp.Controls.Add(divm); divgrgridContent.Controls.Add(divp); HtmlGenericControl diva = new HtmlGenericControl(&#34;a&#34;); HtmlGenericControl divi = new HtmlGenericControl(&#34;i&#34;); diva.Style.Add(&#34;cursor&#34;, &#34;pointer&#34;); diva.Style.Add(&#34;font-style&#34;, &#34;normal !important&#34;); diva.InnerHtml = dt.Rows[0][&#34;PROCESS_NAME&#34;].ToString(); diva.Attributes.Add(&#34;href&#34;, strvarUrl); diva.ID = &#34;divis_&#34; + controlName + &#34;_&#34; + divcnt + &#34;_&#34; + intSubProcess; if (dt.Rows[0][&#34;PROCESS_STATUS&#34;].ToString() == &#34;COMPLETED&#34;) { divi.Attributes.Add(&#34;class&#34;, &#34;fa fa-lightbulb-o green&#34;); } else if (dt.Rows[0][&#34;PROCESS_STATUS&#34;].ToString() == &#34;NEW&#34;) { divi.Attributes.Add(&#34;class&#34;, &#34;fa fa-circle grayborder&#34;); } else if (dt.Rows[0][&#34;PROCESS_STATUS&#34;].ToString() == &#34;PENDING&#34;) { divi.Attributes.Add(&#34;class&#34;, &#34;fa fa-lightbulb-o red&#34;); } divi.Attributes.Add(&#34;aria-hidden&#34;, &#34;true&#34;); divm.Controls.Add(divi); divm.Controls.Add(diva); } } public static string GetSubSubProcesses(string projectId, string currentProcesCode, string processCompleted, string pID) { StringBuilder strsubProcess = new StringBuilder(); //some code return strsubProcess.ToString(); }</pre> <p><span style="text-decoration: underline;"><strong>Screenshot</strong></span></p> <p><img src="https://imgur.com/ff6Jqoy.gif" alt="" width="250" height="204" /></p>https://www.aspforums.net:443/Threads/162040/Add-Underline-and-Bold-to-current-clicked-element-in-JavaScript/https://www.aspforums.net:443/Threads/162040/Add-Underline-and-Bold-to-current-clicked-element-in-JavaScript/Tue, 23 Oct 2018 07:16:40 GMT