homepage Welcome to WebmasterWorld Guest from 54.205.228.154
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
Shouldn't this work on page load?
ZakAltF4




msg:4410767
 6:09 pm on Jan 25, 2012 (gmt 0)

What I am attempting is basic, and I don't understand what I am doing wrong. Does .html change have to be in a function? I must write the content to "js_test" dynamically because it contains multiple divs that try to display simultaneously if javascript is disabled. Looks really bad with JS disabled. This code "looks" right ... But ... lol



<script>
$("#js_test").html('This will be dynamic content run by Javascript ... ');
</script>

<div id="main" class="big-box">
<div class="bg-top">
<div class="bg-bottom">
<!-- Slider -->
<div id="big-slider" class="slider">
<!-- Slider Holder -->
<div id="js_test" class="slider-holder" style="border:solid;">
<noscript>Display Alternate (Non dynamic) Content...</noscript>
</div>
</div>
</div>
</div>
</div>


Any ideas?

 

Marshall




msg:4410777
 6:55 pm on Jan 25, 2012 (gmt 0)

Does it need/have:

<body onload="FUNCTION">

Marshall

ZakAltF4




msg:4410780
 6:57 pm on Jan 25, 2012 (gmt 0)

NO .. Should I put it inside a function and call it from OnLoad? -- On second thought ... We are using an E-commerce CMS, our <body> tag is dynamically generated ... I will have to find another method here ..

Marshall




msg:4410790
 7:11 pm on Jan 25, 2012 (gmt 0)

My JavaScript knowledge is limited and I was just looking at what might have been obvious as I have often overlooked the obvious. (I know, no help) I am sure one of the many experts on WebmasterWorld will be able to help you further.

Marshall

Fotiman




msg:4410804
 7:46 pm on Jan 25, 2012 (gmt 0)

Your script is trying to access #js_test before it exists. Move your script to the end of the page, just before the closing </body> tag and it should work.

rocknbil




msg:4411165
 5:48 pm on Jan 26, 2012 (gmt 0)


$(function(){
$("#js_test").html('This will be dynamic content run by Javascript ... ');
)};

If that doesn't work,

$(window).load(
function() {
$("#js_test").html('This will be dynamic content run by Javascript ... ');
});


You should move it to the bottom in any case, but also get in the habit of wrapping jQuery selectors in $(function()) or $(window).load().

ZakAltF4




msg:4411171
 6:05 pm on Jan 26, 2012 (gmt 0)

Fotiman ... wow .. You know I always try to do that, and in this case it was difficult because of the include structure, and it totally escaped my thought! Thank you for that insight, fixed it right up!

rocknbil, I tried .load, but no avail .. Just needed to move the script under the object...

Thanks all for your insight!

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved