Reputation: 10153
I'm new in jQuery so i have 2 questions.
1-How can I highlight empty space between words in this function?
2-How can I highlight just <abbr class="word p1">
tag?
HTML Code:
<span id="4">
<abbr class="word p1" >ﭢ</abbr>
<abbr class="word p1" >ﭣ</abbr>
<abbr class="word p1" >ﭤ</abbr>
<abbr class="word p1" >ﭥ</abbr>
<abbr class="end p1" >ﭦ</abbr>
</span >
JavaScript Code:
$(function(){
var time = 5;
$("abbr", "#4").each(function(i,e) {
$(e).delay(i*((time*1000)/$("abbr", "#4").length)).animate({'background-color': '#0f0'}, 500);
});
});
Css Code:
span
{
text-align:justify;
float:right;
}
@font-face {
font-family: 'p1';
src: url('http://c216429.r29.cf1.rackcdn.com/p1.eot?#iefix') format('embedded- opentype'),
url('http://c216429.r29.cf1.rackcdn.com/p1.woff') format('woff'),
url('http://c216429.r29.cf1.rackcdn.com/p1.ttf') format('truetype'),
url('http://c216429.r29.cf1.rackcdn.com/p1.svg#p1') format('svg');
}
.p1 {
font-family: 'p1';
}
Demo: http://jsfiddle.net/eTyaV/
Upvotes: 0
Views: 546
Reputation: 185
To highlight only <abbr>
elements with class word p1
just write
$('abbr.word.p1').css({background:'0f0'});
Upvotes: 0
Reputation:
put the spaces inside the <abbr>
.this will solw empty space
<span id="4">
<abbr class="word p1" >ﭢ </abbr>
<abbr class="word p1" >ﭣ </abbr>
<abbr class="word p1" >ﭤ </abbr>
<abbr class="word p1" >ﭥ </abbr>
<abbr class="end p1" >ﭦ</abbr>
</span >
Upvotes: 1
Reputation: 10533
As per my comment above, just include the spaces within the tags to solve your space highlighting issue.
<span id="4">
<abbr class="word p1" >ﭢ </abbr>
<abbr class="word p1" >ﭣ </abbr>
<abbr class="word p1" >ﭤ </abbr>
<abbr class="word p1" >ﭥ </abbr>
<abbr class="end p1" >ﭦ</abbr>
</span >
As for point 2, you could check to see if the element has a class of "word p1" in your each loop, by using a condition like if($(e).hasClass('word')) {}
.
$(function(){
var time = 5;
$("abbr").each(function(i,e) {
if($(e).hasClass('word')) {
$(e).delay(i*((time*1000)/$("abbr").length)).animate({'background-color': '#0f0'}, 500);
}
});
});
Upvotes: 1