Plugging holes in the universe, what are you doing today? RSS 2.0
 Wednesday, May 20, 2009

The other day I was implementing a page block widget using jQuery and BlockUI. The code kinda looked like this:

<a id="testme" href="#">Click Me</a>
                   
<script type="text/javascript">
   
$(document).ready(function() {
       
$('#testme').click(function() {
           
// Set our message in the message panel....
            $('#progressMessage').text('Please wait!');
           
$.blockUI({
               
message: $('#progressWidget')
           
});
       
});
   
}
</script>

<div id="progressWidget" style="display:none" align="center">
   
<div class="modalUpdateProgressMessage">
       
<div id="progressMessage" />
        <
img src="spinbar.gif" />
    </
div>
</div>
 
Pretty stock stuff except I’m using a DOM element to show the page block message.
 
However, for some reason my <img src=”spinbar.gif”/> tag was being overwritten when writing content inside of the ‘progressMessage’ <div> tag even though the <img> tag is a sibling element and not a child.
 
It turns out that using self closing tags, whilst being valid XHTML, causes jQuery to select all siblings of the self-closed tag. Because all the sibling tags of <div id=”progressMessage”/> were selected they were also being overwritten by the code at - $('#progressMessage').text('Please wait!');


The trick it seems is to close empty tags with an explicit closing tag. i.e. <div id=”progressMessage”></div> and then life is good again.

Wednesday, May 20, 2009 12:52:27 AM UTC  #    -

Now Playing
Top Artists This Week
Fluff

Powered by FeedBurner
Categories
Archive
<May 2009>
SunMonTueWedThuFriSat
262728293012
3456789
10111213141516
17181920212223
24252627282930
31123456
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2010
Kevin Kenny
Sign In
Statistics
Total Posts: 207
This Year: 3
This Month: 0
This Week: 0
Comments: 140
All Content © 2010, Kevin Kenny
DasBlog theme 'Business' created by Christoph De Baene (delarou)