Prevent attr() from repeating

Joined
Dec 15, 2009
Messages
1,382
Reaction score
236
http://jsfiddle.net/3NJeg/

Alright, this is it. another freaking problem with JQuery.

As you can see, if u hover on 'CLICK ME 2', data-info will be revealed because it's variable stored isn't equals to '0'. However, if you hover on it again, a blank space will occurs (<span></span>) without any variable. idk why :/
It is actually repeating this codes

Code:
			} else {
				var info2 = '<span>'+$(this).attr('data-info')+'<br /></span>'
				$(this).attr('data-info',info2);
			}
I have no idea how to stop this :(
can anybody give me a hand?
 
Code:
var info2 = '<span>'+$(this).attr('data-info')+'<br /></span>'
$(this).attr('data-info',info2);
Let me simplify it for you to spot the (a) logic error:
Let's say data-info, is FOO in the beginning

First hovering:
var info2 = 'span' + data-info + 'span'
data-info = info2
(attr equals now spanFOOspan)

Second hovering:
var info2 = 'span' + data-info + 'span'
data-info = info2
(attr now equals spanspanFOOspanspan)

Okay, probably you clear it somewhere but this is no way to code anything...
 
Let me simplify it for you to spot the (a) logic error:
Let's say data-info, is FOO in the beginning

First hovering:
var info2 = 'span' + data-info + 'span'
data-info = info2
(attr equals now spanFOOspan)

Second hovering:
var info2 = 'span' + data-info + 'span'
data-info = info2
(attr now equals spanspanFOOspanspan)

Okay, probably you clear it somewhere but this is no way to code anything...

Lol you are right.. I didnt read exactly what he wanted to do with it.. >.<

sent by mobile phone using Tapatalk. please ignore spelling mistakes.
 
Back