Animating HTML Text Change jQuery - javascript

I am attempting to change the text of a HTML element using javascript and jquery. This is my code so far, and I can't seem to get it to work. I have googled it and can't seem to find anything on it.
$("div#title").hover(
function() {
$(this).stop().animate({
$("div#title").html("Hello")
}, "fast");
},
function(){
$(this).stop.animate({
$("div#title").html("Good Bye")
}, "fast");
}
);
Any help would be greatly apreciated.

$("div#title").hover(
function () {
$(this).stop().html("Hello").hide(0).fadeIn("fast");
},
function () {
$(this).stop().html("Good Bye").hide(0).fadeIn("fast");
}
);
jsFiddle example

The way you are doing currently the syntax is incorrect, also you cannot animate a text as such instead you would need to animate an element holding the text. Also not clear on what peoprty you want to animate, Here couple of examples:
Animating Opacity:
$("div#title").hover(
function () {
$(this).stop().css('opacity', '0').html(function (_, oldText) { // Set the opacity of the div to 0 and then change the html (flip it based on last value)
return oldText == 'Good Bye' ? 'Hello' : 'Good Bye'
}).animate({
opacity: 1 // Animate opacity to 1 with a duration of 2 sec
}, 2000);
});
Fiddle
Animating Width:
$("div#title").hover(
function () {
$(this).stop().animate({
'width': '0px' // Animate the width to 0px from current width
}, 2000, function () { // On completion change the text
$(this).html(function (_, oldText) {
return oldText == 'Good Bye' ? 'Hello' : 'Good Bye'
}).animate({ // and animate back to 300px width.
'width': '300px'
}, 2000);
})
});
Fiddle

You can try this also
$("div#title").hover(
function() {
$(this).stop().fadeOut("slow",function(){
$(this).html("Hello")
}).fadeIn("slow");
},
function(){
$(this).stop().fadeOut("slow", function(){
$(this).html("Good Bye")
}).fadeIn("slow");
});

The text can not really encouraged, you can change the content using html method.
Lettering.js is a plugin to play in a more visual with text.
http://letteringjs.com/
$("#title").hover(function(){
$(this).html("Hello");
},function(){
$(this).html("Good Bye");
});

Typing Style
<font size="7" style="position:absolute; left:0px; top:0px; width:150px; z-index:50;">Hello World!</font>
<div id="test" style="position:absolute; left:0px; top:0px; height:100px; width:150px; z-index:60; background-color: #ffffff;"></div>
$('#test').animate({"left" : "150"}, 2000);

I've coded one plugin for that purpose, you can check it on github: jquery-bubble-text.
You can use it this way:
bubbleText({
element: $element, // must be one DOM leaf node
newText: 'new Text', // must be one string
});
Look one example in this jsfiddle.
Hope you enjoy it :)

Select a HTML element.
Here' my example:
<h1 id="heading">Heading1</h1>
<script src="https://code.jquery.com/jquery-2.1.0.js"></script>
<script>
//Changing the text part
$("#heading").text("1Heading");
// No needed code
var read = document.getElementById("heading");
var text = read.value;
console.log(text);
//Should be 1Heading
</script>
Make sure you load the jQuery first:
<script src="https://code.jquery.com/jquery-2.1.0.js"></script>

Related

How can I get the CKEditor Inline Toolbar to fade in and out?

I'm currently using CKEditor in a webapp that I am building. I'd like to have the Inline Toolbar fade in when the text box is focused and fade out when unfocused. I'd normally just add a transition for this but the toolbar seems to be shown/hidden with the Visibility attribute added via a JS file which causes problems.
Does anyone have a good solution for fading the toolbar in and out?
EDIT Adding startup code as requested:
In my HTML I have a div which looks like the following:
<div id="editor" contenteditable="true"></div>
And then in mu .JS file I run the following code:
$(document).ready(function () {
CKEDITOR.disableAutoInline = true;
//More Code
CKEDITOR.inline('editor');
//More Code
}
EDIT 2: Got it half working
So I've managed to get it fading in by using the 'focus' event trigger like so:
var editor = CKEDITOR.instances.editor;
$('#cke_editor').css({ 'opacity': '0' });
editor.on('focus', function () {
$('#cke_editor').css({ 'opacity': '0', "transition": "opacity 0.2s linear" });
setTimeout(function () { $('#cke_editor').css({ 'opacity': '1' }) }, 200);
});
However I cannot seem to get it to fade out again as as soon as the Editor is 'blurred' it gets "Display: none" applied to it programmatically.
Glad it works Conor, here is the full anwswer:
By dynamically adding a styleclass on the blur event, e.g. "always-display", the display: none; is overwritten. A javascript setTimeout can remove this class after the desired blur duration.
HTML/JavaScript/CSS snippet (not live due to cross-origin frame):
var editor = CKEDITOR.replace( 'editor1' );
editor.on('focus', function () {
$('#cke_editor').css({ 'opacity': '0', "transition": "opacity 0.2s linear" });
setTimeout(function () { $('#cke_editor').css({ 'opacity': '1' }) }, 200);
});
editor.on('blur', function () {
//force CKEditor to be visible, by overwriting 'display:none'
$('#cke_editor').addClass("always-display");
//attach fade effect
$('#cke_editor').css({ 'opacity': '0' });
//remove override forcing visibility after fade effect has taken place
setTimeout(function () { $('#cke_editor').removeClass("always-display"); }, 200);
});
.always-display{
display: block !important;
}
<html>
<head>
<script src="//cdn.ckeditor.com/4.6.2/standard/ckeditor.js"></script>
</head>
<body>
<textarea name="editor1" contenteditable="true"></textarea>
<script>
</script>
</body>
</html>
So thank you to DaniëlCamps and PrasadGayan for their help, with it I managed to create my own solution to the problem.
I added the following Focus and Blur event handlers after the Editor is initialised:
var editor = CKEDITOR.instances.editor;
editor.on('focus', function () {
$('#cke_editor').css({ 'opacity': '0', "transition": "opacity 0.2s linear" });
setTimeout(function () { $('#cke_editor').css({ 'opacity': '1' }) }, 200);
});
editor.on('blur', function () {
$('#cke_editor').addClass("always-display");
$('#cke_editor').css({ 'opacity': '0' });
setTimeout(function () { $('#cke_editor').removeClass("always-display"); }, 200);
});
And the Always-Display class looks like:
.always-display{
display: block !important;
}

How to delay jquery hover event

I have a menu with categories,
when I hover on a category a drop down show up
(I have already delayed the drop down to show up after 600 MS),
I want to know how to delay the hover event on the category too for 600 MS,
What is the best way and easiest way to achieve this using jquery?
jQuery('div.dropdown').hover(function() {
jQuery(this).find('.services-shortcut').addClass('active');
jQuery(this).find('.dropdown-menu').stop(true, true).delay(600).fadeIn(0);
}, function() {
jQuery(this).find('.services-shortcut').removeClass('active');
jQuery(this).find('.dropdown-menu').stop(true, true).delay(600).fadeOut(0);
});
I have made a bootply here http://www.bootply.com/lXioubaMre
You could use a basic CSS transition
.services-shortcut {
transition: all 0s .6s;
}
that runs immediately after a 600ms delay
Example: http://www.bootply.com/xppQzbvQ3P
If you choose to do this effect absolutely in javascript (but I wouldn't do it, just to keep off style from javascript) then apply the active class after a 600ms timeout, e.g.
jQuery('div.dropdown').hover(function() {
var $this = $(this);
setTimeout(function() {
$this.find('.services-shortcut').addClass('active');
}, 600);
$this.find('.dropdown-menu').stop(true, true).delay(600).fadeIn(0);
}, ...
If you use this approach then you should also clear the interval onmouseout
You can use hoverIntent jQuery plugin, which triggers functions based on client mouse movement. In your case the script would be simple, you can take a look at this Bootply:
function showMenu(e) {
jQuery(this).find('.services-shortcut').addClass('active');
jQuery(this).find('.dropdown-menu').show();
};
function hideMenu(e) {
jQuery(this).find('.services-shortcut').removeClass('active');
jQuery(this).find('.dropdown-menu').hide();
};
$("div.dropdown").hoverIntent({
over: showMenu,
out: hideMenu,
sensitivity: 3,
timeout: 800
});
$(".dropdown-menu a").hoverIntent({
over: function(){
$(this).addClass('active')
},
out: function(){
$(this).removeClass('active')
},
sensitivity: 3
});
I would use $.hoverDelay() plugin that does exactly that. It lets you configure the delay(s) for the 'in' and 'out' events like so:
$('div.dropdown').hoverDelay({
delayIn: 200,
delayOut:700,
handlerIn: function($element){
$element.css({backgroundColor: 'red'});
},
handlerOut: function($element){
$element.css({backgroundColor: 'auto'});
}
});
You can simply use jQuery.delay() method :
jQuery('div.dropdown').hover(function() {
alert("Action delayed");
jQuery(this).find('.services-shortcut').addClass('active');
jQuery(this).find('.dropdown-menu').stop(true, true).delay(600).fadeIn(0);
}, function() {
jQuery(this).find('.services-shortcut').removeClass('active');
jQuery(this).find('.dropdown-menu').stop(true, true).delay(600).fadeOut(0);
}).delay(600);
.dropdown{
background-color:red;
]
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<div class="dropdown">
aaaa
</div>
That will wait for 600ms before executing your action, that's all you need.

Expand div upon clicking

I created a div that has the full height of it's content set to 500px. First 200px of the 500px is, lets say, a preview. So I set it's height to 200px and overflow: hidden. I then added this script:
<div class="stretcher">
<script type="text/javascript">
$('.stretcher').toggle(
function(){
$(this).animate({'height': '500px'}, 300);
},
function(){
$(this).animate({'height': '200px'}, 300);
}
);
</script>
That works but the problem is that I need the contents of the div to be clickable. However, with this script wherever I click it either expands the div or returns it back to the original 200px.
Any idea how I could do it? Maybe adding icons of arrow up and down or something.
The toggle() function used that way is deprecated and removed in newer versions of jQuery, use a flag instead :
$('.stretcher').on('click', function(e) {
if (e.target === this) {
var h = $(this).height() > 220;
$(this).animate({'height': ( h ? 200 : 500 ) }, 300);
}
});
Checking if the target equals this stops any problems when clicking other elements inside .strecher
Try this...
<div class="stretcher">
<div class="clickable"></div>
</div>
<script type="text/javascript">
$('.clickable').toggle(
function()
{
$(this).parent().animate({'height': '500px'}, 300);
},
function()
{
$(this).parent().animate({'height': '200px'}, 300);
}
);
</script>
You have an area called clickable and when you click that it animates the parent container div, but it won't do it when you click the div itself.
You could wrap your code in a function that has an exact match. As #adeneo points out. An example below using your existing code in this manner.
$('.stretcher').on('click', function(e) {
if (e.target === this) {
$('.stretcher').toggle(
function(){
$(this).animate({'height': '500px'}, 300);
},
function(){
$(this).animate({'height': '200px'}, 300);
}
);
}
});

jQuery UI class switching of multiple elements

Im trying to make the divs change class from "normal" to "thin" ONLY if they have the class "normal". But somehow they just change back and forth, the IF statement seems to be written completely wrong :)
Here is the code
<div class="normal">1</div>
<div class="normal">2</div>
<div class="normal">3</div>
<div class="normal">4</div>
<div class="normal">5</div>
<div class="normal">6</div>
CSS:
.normal{
float:left;
height:200px;
width:100px;
border:1px dotted gray;
}
.thin{
float:left;
width:50px;
height:200px;
border:1px dotted gray;
background-color:#5a5a5a;
}
jQuery
$(document.body).click(function () {
$("div").each(function () {
if ($(this).hasClass("normal")) {
$(this).toggleClass("thin", 300); //Problem here?
} else {
this.style.color = "red";
}
});
});
#Egis as per your requirement the code should like below :
$(document.body).toggle(
function () {
$("div.normal").animate({
width: "50px",
}, "slow", function(){ $(this).addClass("thin"); });
},
function(){
$("div.normal").animate({
width: "100px",
}, "slow", function(){ $(this).removeClass("thin"); });
}
);
DEMO
I hope this is what you are looking for, Good Luck !!
ToggleClass (http://api.jquery.com/toggleClass/) will both add and remove the class. So instead, you want to remove the class "normal" and add the class "thin":
$(this).removeClass("normal").addClass("thin");
Regarding the animation, it looks like you are using the jQueryUI project (sorry I missed the tag, the first time around): http://jqueryui.com/toggleClass/ which allows you to specify an animation duration. With that in mind, you can include the durations:
$(this).removeClass("normal", 300).addClass("thin", 300);
You didn't remove the 'normal' class after you have first reached the code block of your if and your div will always have the 'normal' class, so your condition in your if will always be true.
Use removeClass for that purpose.
Also, if you want to change the class from 'normal' to 'thin', use the addClass for adding thin instead of toggle.
EDIT:
Maybe this is what you want:
$(document.body).click(function () {
$("div").each(function () {
if ($(this).hasClass("normal")) {
$(this).removeClass("normal");
$(this).addClass("thin");
}
else if ($(this).hasClass("thin")) {
$(this).removeClass("thin");
$(this).addClass("normal");
} else {
this.style.color = "red";
}
});
});

Text blinking jQuery

What is an easy way to make text blinking in jQuery and a way to stop it? Must work for IE, FF and Chrome. Thanks
A plugin to blink some text sounds a bit like overkill to me...
Try this...
$('.blink').each(function() {
var elem = $(this);
setInterval(function() {
if (elem.css('visibility') == 'hidden') {
elem.css('visibility', 'visible');
} else {
elem.css('visibility', 'hidden');
}
}, 500);
});
Try using this blink plugin
For Example
$('.blink').blink(); // default is 500ms blink interval.
//$('.blink').blink(100); // causes a 100ms blink interval.
It is also a very simple plugin, and you could probably extend it to stop the animation and start it on demand.
here's blinking with animation:
$(".blink").animate({opacity:0},200,"linear",function(){
$(this).animate({opacity:1},200);
});
just give a blink class whatever u want to blink:
<div class="someclass blink">some text</div>
all regards to DannyZB on #jquery
features:
doesn't need any plugins (but JQuery itself)
does the thing
If you'd rather not use jQuery, this can be achieved with CSS3
#-webkit-keyframes blink {
from { opacity: 1.0; }
to { opacity: 0.0; }
}
blink {
-webkit-animation-name: blink;
-webkit-animation-iteration-count: infinite;
-webkit-animation-timing-function: cubic-bezier(1.0,0,0,1.0);
-webkit-animation-duration: 1s;
}
Seems to work in Chrome, though I thought I heard a slight sobbing noise.
Combine the codes above, I think this is a good solution.
function blink(selector){
$(selector).animate({opacity:0}, 50, "linear", function(){
$(this).delay(800);
$(this).animate({opacity:1}, 50, function(){
blink(this);
});
$(this).delay(800);
});
}
At least it works on my web.
http://140.138.168.123/2y78%202782
Here's mine ; it gives you control over the 3 parameters that matter:
the fade in speed
the fade out speed
the repeat speed
.
setInterval(function() {
$('.blink').fadeIn(300).fadeOut(500);
}, 1000);
You can also use the standard CSS way (no need for JQuery plugin, but compatible with all browsers):
// Start blinking
$(".myblink").css("text-decoration", "blink");
// Stop blinking
$(".myblink").css("text-decoration", "none");
W3C Link
This is the EASIEST way (and with the least coding):
setInterval(function() {
$( ".blink" ).fadeToggle();
}, 500);
Fiddle
Now, if you are looking for something more sophisticated...
//Blink settings
var blink = {
obj: $(".blink"),
timeout: 15000,
speed: 1000
};
//Start function
blink.fn = setInterval(function () {
blink.obj.fadeToggle(blink.speed);
}, blink.speed + 1);
//Ends blinking, after 'blink.timeout' millisecons
setTimeout(function () {
clearInterval(blink.fn);
//Ensure that the element is always visible
blink.obj.fadeIn(blink.speed);
blink = null;
}, blink.timeout);
Fiddle
You can also try these:
<div>some <span class="blink">text</span> are <span class="blink">blinking</span></div>
<button onclick="startBlink()">blink</button>
<button onclick="stopBlink()">no blink</button>
<script>
function startBlink(){
window.blinker = setInterval(function(){
if(window.blink){
$('.blink').css('color','blue');
window.blink=false;
}
else{
$('.blink').css('color','white');
window.blink = true;
}
},500);
}
function stopBlink(){
if(window.blinker) clearInterval(window.blinker);
}
</script>
$.fn.blink = function(times, duration) {
times = times || 2;
while (times--) {
this.fadeTo(duration, 0).fadeTo(duration, 1);
}
return this;
};
Here you can find a jQuery blink plugin with its quick demo.
Basic blinking (unlimited blinking, blink period ~1 sec):
$('selector').blink();
On a more advanced usage, you can override any of the settings:
$('selector').blink({
maxBlinks: 60,
blinkPeriod: 1000, // in milliseconds
onBlink: function(){},
onMaxBlinks: function(){}
});
There you can specify the max number of blinks as well as have access to a couple of callbacks: onBlink and onMaxBlinks that are pretty self explanatory.
Works in IE 7 & 8, Chrome, Firefox, Safari and probably in IE 6 and Opera (although haven't tested on them).
(In full disclosure: I'm am the creator of this previous one. We had the legitimate need to use it at work [I know we all like to say this :-)] for an alarm within a system and I thought of sharing only for use on a legitimate need ;-)).
Here is another list of jQuery blink plugins.
this code is work for me
$(document).ready(function () {
setInterval(function(){
$(".blink").fadeOut(function () {
$(this).fadeIn();
});
} ,100)
});
You can try the jQuery UI Pulsate effect:
http://docs.jquery.com/UI/Effects/Pulsate
Easiest way:
$(".element").fadeTo(250, 0).fadeTo(250,1).fadeTo(250,0).fadeTo(250,1);
You can repeat this as much as you want or you can use it inside a loop. the first parameter of the fadeTo() is the duration for the fade to take effect, and the second parameter is the opacity.
$(".myblink").css("text-decoration", "blink");
do not work with IE 7 & Safari. Work well with Firefox
This stand-alone solution will blink the text a specified number of times and then stop.
The blinking uses opacity, rather than show/hide, fade or toggle so that the DIV remains clickable, in case that's ever an issue (allows you to make buttons with blinking text).
jsFiddle here (contains additional comments)
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var init = 0;
$('#clignotant').click(function() {
if (init==0) {
init++;
blink(this, 800, 4);
}else{
alert('Not document.load, so process the click event');
}
});
function blink(selector, blink_speed, iterations, counter){
counter = counter | 0;
$(selector).animate({opacity:0}, 50, "linear", function(){
$(this).delay(blink_speed);
$(this).animate({opacity:1}, 50, function(){
counter++;
if (iterations == -1) {
blink(this, blink_speed, iterations, counter);
}else if (counter >= iterations) {
return false;
}else{
blink(this, blink_speed, iterations, counter);
}
});
$(this).delay(blink_speed);
});
}
//This line must come *AFTER* the $('#clignotant').click() function !!
window.load($('#clignotant').trigger('click'));
}); //END $(document).ready()
</script>
</head>
<body>
<div id="clignotant" style="background-color:#FF6666;width:500px;
height:100px;text-align:center;">
<br>
Usage: blink(selector, blink_speed, iterations) <br />
<span style="font-weight:bold;color:blue;">if iterations == -1 blink forever</span><br />
Note: fn call intentionally missing 4th param
</div>
</body>
</html>
Sources:
Danny Gimenez
Moses Christian
Link to author
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.1.min.js"></script>
<div id="msg"> <strong><font color="red">Awesome Gallery By Anil Labs</font></strong></p> </div>
<script type="text/javascript" >
function blink(selector){
$(selector).fadeOut('slow', function(){
$(this).fadeIn('slow', function(){
blink(this);
});
});
}
blink('#msg');
</script>
I was going to post the steps-timed polyfill, but then I remembered that I really don’t want to ever see this effect, so…
function blink(element, interval) {
var visible = true;
setInterval(function() {
visible = !visible;
element.style.visibility = visible ? "visible" : "hidden";
}, interval || 1000);
}
I feel the following is of greater clarity and customization than other answers.
var element_to_blink=$('#id_of_element_to_blink');
var min_opacity=0.2;
var max_opacity=1.0;
var blink_duration=2000;
var blink_quantity=10;
var current_blink_number=0;
while(current_blink_number<blink_quantity){
element_to_blink.animate({opacity:min_opacity},(blink_duration/2),"linear");
element_to_blink.animate({opacity:max_opacity},(blink_duration/2),"linear");
current_blink_number+=1;
}
This code will effectively make the element(s) blink without touching the layout (like fadeIn().fadeOut() will do) by just acting on the opacity ; There you go, blinking text ; usable for both good and evil :)
setInterval(function() {
$('.blink').animate({ opacity: 1 }, 400).animate({ opacity: 0 }, 600);
}, 800);
Blinking !
var counter = 5; // Blinking the link 5 times
var $help = $('div.help');
var blinkHelp = function() {
($help.is(':visible') ? $help.fadeOut(250) : $help.fadeIn(250));
counter--;
if (counter >= 0) setTimeout(blinkHelp, 500);
};
blinkHelp();
This code might help to this topic. Simple, yet useful.
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
setInterval("$('#myID/.myClass').toggle();",500);
});
</script>
I like alex's answer, so this is a bit of an extension of that without an interval (since you would need to clear that interval eventually and know when you want a button to stop blinking. This is a solution where you pass in the jquery element, the ms you want for the blinking offset and the number of times you want the element to blink:
function blink ($element, ms, times) {
for (var i = 0; i < times; i++) {
window.setTimeout(function () {
if ($element.is(':visible')) {
$element.hide();
} else {
$element.show();
}
}, ms * (times + 1));
}
}
Some of these answers are quite complicated, this is a bit easier:
$.fn.blink = function(time) {
var time = typeof time == 'undefined' ? 200 : time;
this.hide(0).delay(time).show(0);
}
$('#msg').blink();
Seeing the number of views on this question, and the lack of answers that cover both blinking and stopping it, here goes: try jQuery.blinker out (demo).
HTML:
<p>Hello there!</p>
JavaScript:
var p = $("p");
p.blinker();
p.bind({
// pause blinking on mouseenter
mouseenter: function(){
$(this).data("blinker").pause();
},
// resume blinking on mouseleave
mouseleave: function(){
$(this).data("blinker").blinkagain();
}
});
Indeed a plugin for a simple blink effect is overkill. So after experimenting with various solutions, I have choosen between one line of javascript and a CSS class that controls exactly how I want to blink the elements (in my case for the blink to work I only need to change the background to transparent, so that the text is still visible):
JS:
$(document).ready(function () {
setInterval(function () { $(".blink").toggleClass("no-bg"); }, 1000);
});
CSS:
span.no-bg {
background-color: transparent;
}
Full example at this js fiddle.
Blink functionality can be implemented by plain javascript, no requirement for jquery plugin or even jquery.
This will work in all the browsers, as it is using the basic functionality
Here is the code
HTML:
<p id="blinkThis">This will blink</p>
JS Code:
var ele = document.getElementById('blinkThis');
setInterval(function () {
ele.style.display = (ele.style.display == 'block' ? 'none' : 'block');
}, 500);
and a working fiddle
This is what ended up working best for me. I used jQuery fadeTo because this is on WordPress, which already links jQuery in. Otherwise, I probably would have opted for something with pure JavaScript before adding another http request for a plugin.
$(document).ready(function() {
// One "blink" takes 1.5s
setInterval(function(){
// Immediately fade to opacity: 0 in 0ms
$(".cursor").fadeTo( 0, 0);
// Wait .75sec then fade to opacity: 1 in 0ms
setTimeout(function(){
$(".cursor").fadeTo( 0, 1);
}, 750);
}, 1500);
});
I have written a simple jquery extension for text blink whilst specifying number of times it should blink the text, Hope it helps others.
//add Blink function to jquery
jQuery.fn.extend({
Blink: function (i) {
var c = i; if (i===-1 || c-- > 0) $(this).fadeTo("slow", 0.1, function () { $(this).fadeTo("slow", 1, function () { $(this).Blink(c); }); });
}
});
//Use it like this
$(".mytext").Blink(2); //Where 2 denotes number of time it should blink.
//For continuous blink use -1
$(".mytext").Blink(-1);
Text Blinking start and stop on button click -
<input type="button" id="btnclick" value="click" />
var intervalA;
var intervalB;
$(document).ready(function () {
$('#btnclick').click(function () {
blinkFont();
setTimeout(function () {
clearInterval(intervalA);
clearInterval(intervalB);
}, 5000);
});
});
function blinkFont() {
document.getElementById("blink").style.color = "red"
document.getElementById("blink").style.background = "black"
intervalA = setTimeout("blinkFont()", 500);
}
function setblinkFont() {
document.getElementById("blink").style.color = "black"
document.getElementById("blink").style.background = "red"
intervalB = setTimeout("blinkFont()", 500);
}
</script>
<div id="blink" class="live-chat">
<span>This is blinking text and background</span>
</div>

Categories