Solved

JQuery Span Write

Posted on 2014-07-25
8
240 Views
Last Modified: 2014-07-25
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/
0
Comment
Question by:Richard Morris
  • 5
  • 3
8 Comments
 
LVL 13

Expert Comment

by:duncanb7
ID: 40220938
$('#empty1,#empty2:empty').text("0");

Try this

Duncan
0
 
LVL 13

Expert Comment

by:duncanb7
ID: 40220944
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
0
 

Author Comment

by:Richard Morris
ID: 40220975
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?
0
 
LVL 13

Expert Comment

by:duncanb7
ID: 40220977
it works for  me at my side,
$('(#empty1,#empty2):empty').text("0");
 it might depend on version of jquery

Duncan
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 13

Expert Comment

by:duncanb7
ID: 40220978
Both also works I tested at my server

Duncan
0
 

Author Comment

by:Richard Morris
ID: 40220985
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?
0
 
LVL 13

Accepted Solution

by:
duncanb7 earned 500 total points
ID: 40220987
I am using older one.

Done

Duncan
0
 

Author Closing Comment

by:Richard Morris
ID: 40220997
Great work Duncan!

Here is the reference fiddle:

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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What is a Lightbox? A Lightbox is the effect you see when you click, for example, an image and the screen fades out and up pops the same image but in its full size dimensions. There are lots of Lightbox effects for jQuery. Problem is they are a…
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now