There is a code written in code behind to generate HTML tag's dynamically, upon click of particular tag, inner text must be bold and highlight.
<div>
//dynamically added code from code behind (code taken from browser inspect element)
<p id='ContentPlaceHolder1_divps_subProD__1_0' style='cursor:pointer;' onclick='showSubProcess('f01d668d-9c9d-4907-bd66-128c21c4c32d','FEL1-MCM','1','yes', 'divps_subProD__1_0');'>
PROJECT1
<i> </i>
</p>
</div>
C# code:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//some code
HtmlGenericControl divp = new HtmlGenericControl("p");
divp.ID = "divps_" + controlName + "_" + divcnt + "_" + intSubProcess;
divp.Style.Add("cursor", "pointer");
ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "showSubProcess", "showSubProcess(1,1,1,1)", true);
string processCompleted = "yes";
if (drSubP["PROCESS_STATUS"].ToString() == "0" && currentProcesCode == (drSubP["PROCESS_CODE"].ToString()))
processCompleted = "no";
divp.Attributes.Add("onclick", "showSubProcess('" + projectId + "','" + drSubP["PROCESS_CODE"].ToString() + "','" + divcnt.ToString() + "','" + processCompleted + "', '" + divp.ID + "');");
HtmlGenericControl divm = new HtmlGenericControl("i");
divp.Controls.Add(divm);
divgrgridContent.Controls.Add(divp);
HtmlGenericControl diva = new HtmlGenericControl("a");
HtmlGenericControl divi = new HtmlGenericControl("i");
diva.Style.Add("cursor", "pointer");
diva.Style.Add("font-style", "normal !important");
diva.InnerHtml = drSubP["PROCESS_NAME"].ToString();
diva.Attributes.Add("href", strvarUrl);
diva.ID = "divis_" + controlName + "_" + divcnt + "_" + intSubProcess;
if (drSubP["PROCESS_STATUS"].ToString() == "COMPLETED")
divi.Attributes.Add("class", "fa fa-lightbulb-o green");
else if (drSubP["PROCESS_STATUS"].ToString() == "NEW")
divi.Attributes.Add("class", "fa fa-circle grayborder");
else if (drSubP["PROCESS_STATUS"].ToString() == "PENDING")
divi.Attributes.Add("class", "fa fa-lightbulb-o red");
divi.Attributes.Add("aria-hidden", "true");
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();
}
Javascript code:
<style type="text/css">
.mystyle
{
color:black;
font-weight:bold;
text-decoration:underline;
}
</style>
<script>
function showSubProcess(projid, curProcessId, processId, processCompleted, pID)
{
if (projid != 1)
{
$('#loadingmessage').show();
//code to underline and bold selected text
var element1 = document.getElementById("ContentPlaceHolder1_" + pID);
element1.classList.add("mystyle");
globalProcessId = processId;
var contPalaceH = "ContentPlaceHolder1_divgrgridContent_subProD_" + processId;
var data = document.getElementById(contPalaceH);
var href = window.location.href.split('/');
var root = href[0] + '//' + href[2] + '/' + href[3];
$.ajax({
type: "POST",
url: root + "/Project/Home_New.aspx/GetSubSubProcesses",
data: '{ projectId: "' + projid + '", currentProcesCode: "' + curProcessId + '",processCompleted:"' + processCompleted + '",pID:"' + pID + '"}',
contentType: "application/json; charset=utf-8",
async: true,
cache: false,
dataType: "json",
success: OnSuccessData,
failure: function (response) {
$('#loadingmessage').hide();
alert(response.d);
}
});
}
}
</script>
Below 2 line of code is written to make current/last/latest selected/clicked text bold and underline:
//code to underline and bold selected text
var element1 = document.getElementById("ContentPlaceHolder1_" + pID);
element1.classList.add("mystyle");
but instead of current, all selected/clicked text is bold and underline.
Please let me know how to make only current/latest selected/clicked text bold and underline ?
Thanks in advance