-2

I have been using "overflow-wrap: break-word;" in a CSS class and the element having that class.

Long story but I want to hard code the style into the element, however there doesn't seem to be a syntax for overflow-wrap via element.style....

JQuery
  • 889
  • 3
  • 13
  • 35

2 Answers2

0

You can apply css to an object using jQuery like this:

$('#element').css('overflow-wrap', 'break-word');
Wouter Bouwman
  • 1,003
  • 6
  • 13
  • I know, but as I am building the element up I was hoping to add it via the style method with the others. Is it possible? – JQuery Oct 19 '17 at 09:16
  • Have you looked into the css styles wordWrap and wordBreak? https://stackoverflow.com/questions/17259916/difference-between-overflow-wrap-and-word-break – Wouter Bouwman Oct 19 '17 at 09:28
  • Do you mean an inline style on the element itself, or adding a style block to the head of the page (if it's the former, OP's solution does exactly that, if it's the latter you may want to clarify in your question). – delinear Oct 19 '17 at 09:28
0

If you are dynamically adding elements then I would suggest you write this as a function that is called whenever a new element is added, probably using an event listener, that you can pass your updated style values to as parameters. Something like:

updateDOMStyle('<style>','<value>');
Cons7an7ine
  • 708
  • 6
  • 17