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)+'­');
}
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>wit开发者_开发问答hlotsots</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?
精彩评论