Solved

Help using .after()

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Making an "H1" a specific color only on a specific page. 3 31
JavaScript Loan Calculator Error 3 34
converting document.write() to innerHTML 7 44
Jquery 7 28
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

735 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