Use jquery's toggle in Moodle

Use jquery's toggle in Moodle

על ידי David Dubois בתאריך
מספר תגובות: 7

Hi,

I declared jquery and it works :

<script src="http://tmoodle.ulb.ac.be/pluginfile.php/2803/mod_resource/content/1/jquery.js" type="text/javascript">// <![CDATA[
>
<script type="text/javascript">// <![CDATA[
alert(jQuery.fn.jquery);
// ]]>
// ]]></script>

Now I would like to use toogle with this code :

<script type="text/javascript">// <![CDATA[
$('#toggle1').click(function() {
    $('.toggle1').toggle();
    return false;
});
// ]]></script>
<p id="toggle1">Simple Div Toggle<br /><br /></p>
<div class="toggle1" style="display: none; background-color: #4cf; width: 100px; height: 100px;"></div>

I obtain this error :

 
detailed error: Error: Syntax error, unrecognized expression: &gt;ul
error source line:
 
 
throw new Error( "Syntax error, unrecognized expression: " + msg );
Have you an idea of how to resolve this problem ?
 
Thank you in advance for your help
   
ממוצע דרוגים: -
בתגובה ל: David Dubois

Re: Use jquery's toggle in Moodle

על ידי Mauno Korpelainen בתאריך

Check the syntax ... קריצה

At least in your example the first script tag is not closed at all.

בתגובה ל: Mauno Korpelainen

Re: Use jquery's toggle in Moodle

על ידי David Dubois בתאריך

Hi,

Thanks for your reply.

This code is added by Moodle automaticaly :

// <![CDATA[

I don't know why.

My code seems to be right ?

Thanks in advance for help.

David

 

בתגובה ל: David Dubois

Re: Use jquery's toggle in Moodle

על ידי Brian Merritt בתאריך

Could be a number of issues, such as jQuery not being loaded correctly, there being conflict issues with $, jQuery version conflict if multiple are loaded etc.  Does the script work OK in jfiddle or similar?

 

בתגובה ל: David Dubois

Re: Use jquery's toggle in Moodle

על ידי Mauno Korpelainen בתאריך

Moodle 2.x is using HTML5 and self-closing script tags don't work in HTML5. So I would add that missing </script> tag there ...

בתגובה ל: David Dubois

Re: Use jquery's toggle in Moodle

על ידי Andrew Lyons בתאריך
תמונה של Core developers תמונה של Moodle HQ תמונה של Particularly helpful Moodlers תמונה של Peer reviewers תמונה של Plugin developers תמונה של Testers

Hi David,

I'd recommend looking at the post the Darko linked. There's also appropriate documentation on the correct way of including jQuery in Moodle at http://docs.moodle.org/dev/jQuery.

It would help if you gave some information on how you generated the above code too.

Best wishes,

Andrew Nicols