Message from JavaScript talks

July 2017

— But how?

— 

const listItem = $('<ons-list-item modifier="chevron" tappable ripple class="tombolmenu">');

const p = $('<p>');

p.text(el.nama);

listItem.append(p);

listItem.click(...);

$('#datalist').append(listItem);

— 

$('#datalist').append('<ons-list-item modifier="chevron" tappable ripple class="tombolmenu"><p>'+ el.nama +'</p></ons-list-item>');

i get it, but doesnt know how and where to write .click in this line of code.

Message permanent page

— I see, i will try it

— Wait TRGWII is i need to write my whole bukapaket() function inside that listItem.click(...); ?

— You CAN do that

— Or a function that calls it

— Wew, this all make me confused,
well, last question, hope you doesnt bothered and can help me TRGWII
i have change the code to this :

listItem.click(
function bukapaket() {
document.querySelector('#coreNavigator').pushPage('harga.html');
event.target.querySelector('ons-toolbar .center').innerHTML = el.nama;
console.log("ID dari halaman ini adalah "+el.id+" , dan Nama dari halaman ini adalah "+el.nama+" , dan ini adalah Halaman Harga");
});
$('#datalist').append(listItem);


why that .innerHTML resulted as null but that el.nama appear in console.log ?

Message permanent page

— Uhhh, why use event.target?

— And please don't use innerHTML

— Use .textContent

— Erm, event.target is from a mobile framework that i used i think 😅 i doesn't know if that event.target is from native js or customized one.

Message permanent page