Javascript help please!
- Started
- Last post
- 16 Responses
- effour
I have this code:
<script type="text/javascript">$(document).ready(function...</script>That renders like:
<script type="text/javascript">$(document).ready(function());</script>and fire bug is giving this error:
missing { before function body
[Break on this error] $(document).ready(function());I can't figure it out for the life of me...can nyone lend a hand to help me get to the bottom of this?
Thanks!
- acescence0
use this or post it somewhere
- effour0
this is the code, got cut off up there:
<script type="text/javascript">
$(document).ready(function() {
$('code.javascript').runcode();
});
</script>
- acescence0
hm, need to see more to understand what's happening. that's a bit of jquery but i'm not exactly sure what you're trying to do here? are you actually using jquery and you've sourced it on the page?
- neverblink0
I guess you already know, but there is no "runcocde" function in (default) jQuery..
- effour0
For some reason it's stripping code when the page renders:
it should look like:
<script type="text/javascript">
$(document).ready(function() {
$('code.javascript').runcode();
});
</script>instead it strips it to:
<script type="text/javascript">
$(document).ready(function() );
</script>Anyone know why it would be doing that?
Thanks.
- acescence0
like i said, we need to see more. that code on it's own is not valid and does nothing.
- neverblink0
which element are you trying to access and run.. a javascript-script?
- effour0
ya, this is the script:
http://www.trovster.com/lab/codeā¦
- neverblink0
have you tried giving the script an id, and replacing the code.javascript in your code with #id to test id the selecting of the scripts actually works?
- test if..neverblink
- no, i haven't no idea how to even do that...
effour
- neverblink0
you're probably way out of your league if you don't know how to add an id to your script element.. but what the hey, I'm feeling generous..
//-- in your < head >
<script type="text/javascript">
$(document).ready(function() {
$('#test').runcode();
});
</script>//-- in your < body >
<script type="text/javascript" id="test"> alert("hello world"); </script>
- effour0
thanks neverblink... and i'm so out of my league!!
Your script worked and I got the 'hello world' message....
now what???
- neverblink0
Ok, now we know it's not the runcode() part, but it's the selection part..
Do you want all javascripts on your page to be executed?
Change the runcode line in the script in the head to:$('code[type=javascript]').runco...
- effour0
Updated the code to:
<script type="text/javascript">
$(document).ready(function() {
$('code[type=javascript]').runco...
});
</script>Still getting this error:
missing { before function body
[Break on this error] $(document).ready(function() );\n- little bit is cut off there but it's entered correctly...effour
- neverblink0
hmm..
How about we try something else?<script type="text/javascript">
$(document).ready(function() {
$('code[type=javascript]') .alert( $(this).innerHTML );
});
</script>!! remove the extra space before ".alert...", it is there because otherwise QBN will cut it off.
- effour0
still nothing...just sent you an email...have a read