Solved

JQuery Span Write

Posted on 2014-07-25
8
246 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
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

Get Actionable Data from Your Monitoring Solution

Your communication platform is only as good as the relevance of the information you send. Ensure your alerts get to the right people every time with actionable responses. Create escalation rules that ensure everyone follows the process and nothing is left to chance.

Question has a verified solution.

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

Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28372511.html) on how to make a page show some balloons animate up a page…
PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
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…

690 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