Solved

Help using .after()

Posted on 2011-09-30
2
265 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
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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

Suggested Solutions

Introduction Got endorsements from your clients?  Great!  There is almost nothing better than word-of-mouth advertising.  But how can you do that on the internet?  Sure you can make a page for endorsement quotations and list them all, but who is …
This article discusses how to create an extensible mechanism for linked drop downs.
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…

839 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