Welcome to WebmasterWorld Guest from 54.146.246.4

Forum Moderators: open

Message Too Old, No Replies

Shouldn't this work on page load?

     

ZakAltF4

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

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

WebmasterWorld Senior Member 10+ Year Member



Does it need/have:

<body onload="FUNCTION">

Marshall

ZakAltF4

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

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

WebmasterWorld Senior Member 10+ Year Member



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

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

WebmasterWorld Senior Member fotiman is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



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

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

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member




$(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

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!