I have a repeater control in my web app which consists of a dropdown, I am manipulating this dropdown behaviour (by adding some custom styles) on the change
event. The problem is when I am using the jquery css
property to fetch the background-color value it is returning me the value which was set earlier but not the updated value. But the strange thing is when i am using the attr
property to get the style attribute, it is giving me the correct output but obviously I can't use that because i need specific style.
Here is my rendered dropdown:-
<select name="ct100$rptCurrentData$ct101$ddlIncludeData" class="clsTypes"
id="ctl00_rptCurrentDatas_ddlIncludeData_0" style="background-color: transparent;">
<option style="background-color: transparent;" value="-1">Select</option>
<option style="background-color: transparent;" value="1">Activity</option>
<option style="background-color: rgb(231, 251, 189);" value="2">Proposal</option>
<option style="background-color: transparent;" value="3">Both</option>
</select>
I am overwriting the background-color of selected dropdown using:-
$(this).find('option:selected').css("backgroundColor", '#E7FBBD');`
And as we can see in the rendered HTML, it is updating fine. But my problem is while retrieving the same, I am getting correct value with .attr("style")
but not with .css
Why?
$(this).find('option:selected').css('background-color')); //Output-rgb(10, 36, 106)
$(this).find('option:selected').css('backgroundColor')); //Output-rgb(10, 36, 106)
$(this).find('option:selected').attr("style"));
//Output- background-color: rgb(231, 251, 189);