Welcome to WebmasterWorld Guest from 54.144.114.177

Forum Moderators: open

Message Too Old, No Replies

Shouldn't this work on page load?

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

New User

joined:Jan 12, 2012
posts: 38
votes: 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?
6:55 pm on Jan 25, 2012 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member 10+ Year Member

joined:Sept 4, 2001
posts:2144
votes: 7


Does it need/have:

<body onload="FUNCTION">

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

New User

joined:Jan 12, 2012
posts: 38
votes: 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 ..
7:11 pm on Jan 25, 2012 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member 10+ Year Member

joined:Sept 4, 2001
posts:2144
votes: 7


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
7:46 pm on Jan 25, 2012 (gmt 0)

Senior Member from US 

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

joined:Oct 17, 2005
posts:4966
votes: 10


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.
5:48 pm on Jan 26, 2012 (gmt 0)

Senior Member

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

joined:Nov 28, 2004
posts:7999
votes: 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().
6:05 pm on Jan 26, 2012 (gmt 0)

New User

joined:Jan 12, 2012
posts: 38
votes: 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!
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members