MarcoC
MarcoC

Reputation: 45

jQuery programatically change font family in a checkboxlist

I wanna change the font family for some "elements" in the checkboxlist, I'm trying this code but it doesnt works:

Method (atm I'm changing the text color and font family in the code behind but I wanna do it with jQuery):

private void bindCheckBoxList()
        {
            using (SPWeb web = new SPSite(SPContext.Current.Site.Url).OpenWeb())
            {
                foreach (SPWeb currentWeb in web.Site.AllWebs)
                {
                    string webTitle = currentWeb.Title;

                ListItem myWebItem = new ListItem();
                myWebItem.Text = webTitle;
                myWebItem.Value = currentWeb.Url;
                myWebItem.Attributes.Add("id", "cbBold_" + webTitle);
                myWebItem.Attributes.Add("style", "color: red; font-weight: bold");
                CbList.Items.Add(myWebItem);

                foreach (SPList currentList in currentWeb.Lists)
                {
                    string listTitle = currentList.Title;

                    ListItem myListItem = new ListItem();
                    myListItem.Text = listTitle;
                    myListItem.Value = web.Url + ";" + currentList.Title;
                    myListItem.Attributes.Add("id", "cb_" + listTitle);

                    CbList.Items.Add(myListItem);

                    if (currentList.BaseType == SPBaseType.DocumentLibrary)
                    {
                        myListItem.Text = listTitle + "(Document Library)";
                    }
                    else
                    {
                        myListItem.Text = listTitle + "(List)";
                    }
                }
            }
        }
    }

HTML:

<asp:CheckBoxList ID="CbList" runat="Server" OnSelectedIndexChanged="CbList_SelectedIndexChanged" BulletStyle="NotSet" ClientIDMode="Static">
</asp:CheckBoxList>

jQuery:

 $("[id^=CbBold]").css({ 'font-weight': 'bold' });

Upvotes: 1

Views: 54

Answers (1)

YSuraj
YSuraj

Reputation: 417

You have declared myWebItem "id" as "cbBold_", alter the id.

$("[id^=cbBold_]").css({ 'font-weight': 'bold' });

Upvotes: 2

Related Questions