简体   繁体   中英

How to add html attributes in this JQuery

I'm still new in this area, have few questions.

I have JQuery from this site: http://goskylar.com/wp-content/demos/jquery.hyphenate/

It is solve my problem regarding hyphenation. However, when I put some html tag such as <strong> or <u> the result shows no effect. My question is:
Where and how should I add the function for css attribut so that it can shows the <strong> or <u> results?

--edited--

<script>
(function($){$.fn.hyphenate=function(options) {
   settings=$.extend({oWidth:this.width()},options);

return this.each(function(){
  $(this).css({
    'width':settings.oWidth,
    'display':'block'
  });
  var str='';
  $.each($(this).text().split(' '),function(i,chunk){str+=splitChunk(chunk)+' ';});
  $(this).html(str);    
});

function splitChunk(str){
  if($('<span></span>').text(str).hide().appendTo(document.body).width() > settings.oWidth)
  {var s=''; var i=0;
    while(i < str.length)
    {
      s+=(str.slice(i,++i)+'&shy;');
    }
    return s;
  }
  else
    return str;
    }
  };

})(jQuery);
</script>

<html>
<head>
<title>Hyphenation</title>
</head>
<body>

<script>
jQuery(document).ready(function(){
    $('#d4').hyphenate({oWidth:158});
});
</script>

<div id="d4">this will start with <u>spaces and this firstthisi<strong>sareallylongsentence</strong>withlotsots</u>andlotsofwords</div>
</body>
</html>

About #2, You want to add/change an attribute on an element? jQuery doc and example

More about jQuery Attributes

About #1, can you elaborate more? What query are you talking about?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM