Reputation: 33
I am learning JavaScript and testing things. I have made a text-area which takes some html code and prints the result out.Its working well but I want that whenever a tag is typed like <h1>
the color should change from white to red. This is my code which does not do so, Please help me in fixing it ..
Code:
<script>
$("#_co").on("input propertychange", function(){
$("#out").html($("#_co").val());
var text = jQuery("#_co").val();
if (text.contains("<")){
text.css('color','red');
}
}); </script>
Upvotes: 0
Views: 76
Reputation: 122
There no direct way to achieve the same, but this would help you work around
Pls have a look
function divClicked() {
var divHtml = $(this).html();
var editableText = $("<textarea />");
editableText.val(divHtml);
$(this).replaceWith(editableText);
editableText.focus();
// setup the blur event for this new textarea
editableText.blur(editableTextBlurred);
}
function editableTextBlurred() {
var html = $(this).val();
var viewableText = $("<div>");
viewableText.html(html);
$(this).replaceWith(viewableText);
// setup the click event for this new div
viewableText.click(divClicked);
}
$(document).ready(function() {
$("div.div").click(divClicked);
});
Upvotes: 1