javascript - Button that makes textarea text bold -
i have button has onclick="bold()"
, supposed changing font weight normal bold , normal. isn't doing though. need change or add? here jsfiddle if helps: http://jsfiddle.net/dzvfh/
<script> var x = document.getelementbyid('description-box'); function bold() { if( $(x).css("font-weight") == "normal") { $(x).css("font-weight"), "bold"); } else { $(x).css("font-weight", "normal"); } } </script>
there syntax error in code:
change
$(x).css("font-weight"), "bold");
to
$(x).css("font-weight", "bold");
full function
function bold() { var x = $('#description-box'); if (x.css("font-weight") !== "bold") { x.css("font-weight", "bold"); } else { x.css("font-weight", "normal"); } }
working fiddle: http://jsfiddle.net/dzvfh/3/
there number of problems in original fiddle.
jquery not being included
the function defined inside
domready
- means isn't visible when clicking buttonthe css block had syntax error. style being closed
)
instead of}
you trying assign element
x
before dom ready. new fiddle inside function (by time dom ready)
Comments
Post a Comment