Henk
Henk

Reputation: 704

jTemplates escape {$

is there a way with jTemplates to escape {$, so i can use inline javascript in my onBlur like

<a href="http://www.telegraaf.nl" onclick="if ( a ) {$('#something').css    ('display','none');alert('some msg');}">telegraaf</a>

which gets this after processTemplate:

<a onclick="if ( a ) " href="http://www.telegraaf.nl">

Thanks, Henk

Upvotes: 3

Views: 2069

Answers (5)

great_llama
great_llama

Reputation: 11729

jTemplates has a {#literal} ... {#/literal} tag that should prevent your curly braces from being affected.

<a href="http://www.telegraaf.nl" onclick="{#literal}if ( a ) {$('#something').css    ('display','none');alert('some msg');}{#/literal}">telegraaf</a>

Upvotes: 8

RaYell
RaYell

Reputation: 70414

If you don't want to move your JS to separate secion or external file then you can always use jQuery "keyword" instead of $

<a href="http://www.telegraaf.nl" onclick="if( a ) {jQuery('#something').css('display','none');alert('some msg');}">telegraaf</a>

This way $ won't be interpreted as a template variable.

Upvotes: -1

andres descalzo
andres descalzo

Reputation: 14967

var test = function(el) {
   if ( a ) {
      $('#something').css('display','none');
      alert('some msg');
    }   
});

<a onclick="test(this);" href="http://www.telegraaf.nl">

Upvotes: -2

Wolfwyrd
Wolfwyrd

Reputation: 15916

If you're using jQuery then the $ is essentially just a shortcut to saying jQuery(expression) so in your case you can use:

<a href="http://www.telegraaf.nl" onclick="if ( a ) {jQuery('#something').css    ('display','none');alert('some msg');}">telegraaf</a>

You can read up on the selector shortcut at http://docs.jquery.com/%24

Upvotes: -1

Andreas Grech
Andreas Grech

Reputation: 107950

Actually, in my opinion, I think its best to attach the event unobtrusively :

$(function () {
    $(".alink").click(function () {
        //if ( a ) {
            $('#something').css('display','none');
            alert('some msg');
        //}   
    });
});

<a class="alink" href="http://www.telegraaf.nl">

Upvotes: 3

Related Questions