Solved

Help using .after()

Posted on 2011-09-30
2
271 Views
Last Modified: 2012-06-27
I have the following function that, when a option item is changed, it replaces it with a 'please wait' prompt:

function showLoadingSideText(ctrl) {
	$(ctrl).hide().after('<span style="font-weight:bold; white-space:nowrap; color:#999999"><img src="/images/waiticon.gif" alt="" /> Loading, please wait...</span>');
}

Open in new window


It is invoked like this:

<select id="ddl_site" onchange="showLoadingSideText(this);" />

Open in new window


What I need to do if possible is to expand this code to set the width of the replacing span to be the same as the element that is being hidden.  This would prevent any movement of content around the control being hidden (e.g. table cells suddenly resizing because the content was much smaller).  I've managed to read the size of the element to hide...

function showLoadingSideText(ctrl) {
 var controlWidth = $(ctrl).width();
 window.alert(controlWidth);
	$(ctrl).hide().after('<span style="font-weight:bold; white-space:nowrap; color:#999999"><img src="/images/waiticon.gif" alt="" /> Loading, please wait...</span>');
}

Open in new window


...but I have some questions on the next step:

1. How do I apply the value of controlWidth into the span I am adding using after() ?
2. Why does the window.alert() message fail to show when using IE7 or IE8 (works fine in IE6,9,10 and FF)?  This might be an IETester bug though - but would like some feedback please!

Thanks.
0
Comment
Question by:Rouchie
[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
2 Comments
 
LVL 9

Expert Comment

by:richard_hughes
ID: 36890888
Hello Rouchie

1)

The easist way to control with width of elements is by using CSS. Try adding a common class to both the <select> and the <span> as in the attached code sample.

2)

IETester is not very good with JavaScript. It is mainly used for display testing. A good way to test JavaScript in other browsers is to try them directly. Have a look here for some virtual machines which come pre-installed with the respective browser versions (IE 6, 7, 8, 9): http://www.microsoft.com/download/en/details.aspx?id=11575

Thanks,

Richard Hughes
.commonWidth
{
    width: 150px;
}

Open in new window

0
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 36891002
function showLoadingSideText(ctrl) {
 var controlWidth = $(ctrl).width();
 window.alert(controlWidth);
      $(ctrl).hide().after('<span style="font-weight:bold; white-space:nowrap; color:#999999;width:' + controlWidth +'px;"><img src="/images/waiticon.gif" alt="" /> Loading, please wait...</span>');
}
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
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 the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
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…

630 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