0

again with a problem

This is my dynamic created content:

var content =
      $('<div data-role="collapsible" id="set"' + naslov + '">'+
            '<h3>Sectionit ' + naslov + '</h3>'+
            '<p>' + opis + '</p>'+
            '<a data-ajax="false" href="#" onclick="poslinapri('+niz+')" class="ui-btn ui-shadow ui-corner-all"><div class="prostor1tr">More</div></a>'+
         '</div>');

the problem is that I want in the onClick function to pass a sting not a variable .... lets say that var niz= "hello" .... but I want it to apper as onclick="poslinapri('hello')...

I tried a few things with quotes and double quotes ... but no success ... so can anybody help me here ?

thanks

2 Answers 2

2

You need to escape your single quotes with backslashes, as is often the case with several levels of embedded single/double quotes.

var content =
      $('<div data-role="collapsible" id="set"' + naslov + '">'+
            '<h3>Sectionit ' + naslov + '</h3>'+
            '<p>' + opis + '</p>'+
            '<a data-ajax="false" href="#" onclick="poslinapri(\''+niz+'\')" class="ui-btn ui-shadow ui-corner-all"><div class="prostor1tr">More</div></a>'+
         '</div>');

Here is a simple example to illustrate the point

var content = 'Bob\'s Burgers';
alert(content);

will yield an alert box with Bob's Burgers

Sign up to request clarification or add additional context in comments.

1 Comment

You're most welcome. Make sure that any text in the niz variable is replacing ' with \' as well. Happy Coding.
0

You can do it like this (after you created content):

content.find('.ui-btn').click(function() {
  poslinapri(niz)
});

Thus you dont have to write onclick="poslinapri('+niz+')"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.