Link to home
Start Free TrialLog in
Avatar of Richard Morris
Richard MorrisFlag for Canada

asked on

JQuery Span Write

I need a zero written into empty spans if they are empty, else no change required.

Example:

<span id="empty1"></span> // change to <span id="empty1">0</span>

<span id="empty2">1</span> // no change required

Example fiddle:

http://jsfiddle.net/RichardMorris/D5XJ6/
Avatar of duncanb7
duncanb7

$('#empty1,#empty2:empty').text("0");

Try this

Duncan
Ignore my previous post

Try this,

$('(#empty1,#empty2):empty').text("0");

it should work
Please read the :empty selector at jquery site
http://api.jquery.com/empty-selector/

Duncan
Avatar of Richard Morris

ASKER

Hello Duncan,

Doesn't work in my template but this does:

$('#empty1:empty,#empty2:empty').text("0");

Let me know if this will be okay?
it works for  me at my side,
$('(#empty1,#empty2):empty').text("0");
 it might depend on version of jquery

Duncan
Both also works I tested at my server

Duncan
1.10.2 is what's on the server and I can't change it to older.

So what works best for 1.10.2 requirements?
ASKER CERTIFIED SOLUTION
Avatar of duncanb7
duncanb7

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Great work Duncan!

Here is the reference fiddle:

http://jsfiddle.net/RichardMorris/D5XJ6/1/