Reputation: 321
I am working on my jquery script to find the style with the color and the rgb that I want to find to replace it with #444444
. I have got a problem with find the style color because when I try this:
$('#text_editor').find('[style*="color: rgb(68, 68, 68)]"').css('color', '#444444');
It wont let me to find the style with the color and rgb as it wont replace it.
I have also tried this:
$('#text_editor').find('color: rgb(68, 68, 68)').css('color', '#444444');
And this:
document.execCommand('foreColor', false, '#444444');
$('#text_editor').find("span[style*='color: rgb(68, 68, 68)']").css('color', '#444444');
It make no different as I am keep getting this:
<span style="color: rgb(68, 68, 68);">sdgsdgsdgsdgsdg</span>
Here is what I want to achieve:
<span style="color: #444444;">sdgsdgsdgsdgsdg</span>
Here is the html:
<div id="text_editor" class="editor_message" hidefocus="false" aria-label="Message Body" g_editable="true" role="textbox" aria-hidden="true" aria-multiline="true" contenteditable="true" tabindex="1" style="direction: ltr; height: 500px; width: 100%; padding-left: 25px; padding-top: 18px; font-size: 16px; border-bottom: 1px solid #d1d1d1; border-right: 1px solid #d1d1d1; border-left: 1px solid #d1d1d1; overflow-y: auto;" itacorner="6,7:1,1,0,0">
<span style="color: rgb(68, 68, 68);">sdgsdgsdgsdgsdg</span>
</div>
Here is the full code:
$(document).on('click', '#color-picker1', function(e) {
$('#color-picker' + colorpicker_number + ' div').removeClass('tick-color');
$('#color-picker' + colorpicker_number).removeClass('color-picker-border');
$('#color-picker1 div').addClass('tick-color');
$('#color-picker1').addClass('color-picker-border');
colorpicker_number = 1;
alert("time to change the color 6");
document.execCommand('styleWithCSS', 0, true);
document.execCommand('foreColor', false, '#444444');
$('#text_editor').find('[style*="color: rgb(68, 68, 68)"]').css('color', '#444444');
if ($('#toolbar_text_color').css('display') == 'block') {
$('#toolbar_text_color').hide();
}
$('#text_editor').focus();
});
Can you please show me an example how I can find the style with the rgb color that I want to find before I could use css to replace it with #444444
?
Thank you.
Upvotes: 0
Views: 299
Reputation: 76
it wont change if you are using it in a div or other element.
the only thing i know it will be visible is when you do it with background-color css.
<div style="background-color: #444444;">
...
</div>
Upvotes: 1