Solved

JQuery Span Write

Posted on 2014-07-25
8
244 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
How our DevOps Teams Maximize Uptime

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

 
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
 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
jQuery on click requires double click 6 31
Popup write two lines 3 22
Getting selected value using Jquery 3 20
Add somewhat of a wildcard to your javascript 12 30
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…

749 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