In these cases it is better to create the element on another line and use the jQuery methods to put the dynamic values in the appropriate places:
var button = $("<button class='ui-btn ui-corner-all optCurso' data-transition ='slide'></button>");
button.click(function () { controller.setNomeCurso(cursos[i].Value); });
button.text(cursos[i].Name);
$("#cursos").append(button);
(depending exactly on where i
comes from, you may need something like button.click((function (nomeCurso) { return function () { controller.setNomeCurso(nomeCurso); }})(cursos[i].value));
to capture the closure right)
You will also need to enter a type="button"
if this button appears inside a form.
Do you really need to do this with jQuery?
var button = document.createElement('button');
button.type = 'button';
button.className = 'ui-btn ui-corner-all optCurso';
button.setAttribute('data-transition', 'slide');
button.addEventListener('click', function () { controller.setNomeCurso(cursos[i].Value); }, false);
button.appendChild(document.createTextNode(cursos[i].Name));
document.getElementById('cursos').appendChild(button);
This works on any IE 8+; if you accept to be compatible only with IE 11 and Edge, you can change button.setAttribute('data-transition', 'slide')
to button.dataset.transition = 'slide'
.
jQuery encourages this style of code , concatenating strings; this problem you encountered is the newest cousin of SQL Injection. Concatenating strings to generate HTML tags is to ask to create XSS holes in your application.