If textbox contain a specific string do some function - javascript -
i wondering how search specific string in big textbox (which contains 200 words) can make function color them. ex. in textbox there sentence "my dog happy" , want string "dog" become red button or sth else. possible???
yes, possible. don't use text box or text area, use div contenteditable = "true":
<div id="editablediv" class="editable" contenteditable="true"> sentence containing 'dog'.<br /> can edit contents of div. </div> <button id="highlightbtn">highlight "dog"</button> <script type="text/javascript"> highlightbtn.onclick = function() { var elem = document.getelementbyid('editablediv'); elem.innerhtml = elem.innerhtml.replace(/dog/g, '<span class="redtext">dog</span>'); } </script> and don't forget create classes redtext , editable in stylesheet:
.editable { padding: 5px; border: dashed 1px black; } .redtext { color: red; } jsfiddle: http://jsfiddle.net/programfox/ummph/
Comments
Post a Comment