Can't click an icone after modification by jQuery
Hello,
I have a table structure and in a <td> an image, a language flag icone. When one click on this icone, a jqueryUI popup form present some radio buttons with all languages avalaibles.
If the ok button is clicked, with ajax the database is updated and the new flag replace the old one. All that works fine.
But now, if I click this new flag it is not seen by jQuery. I read in the jQuery documentation that .on() would be the solution to this problem. But I can't understand how to use it.
The img balise has the class "clelangue", and the parent td the id "lang-XX" where XX is the id of the user concerned by the language change. The changeLanguage function does the database update with ajax and change the icone flag. The #changelanguage element is a div : <div id="changelanguage"></div>. #id_f1 is in my php form.
Is the line :
- "$( 'td[id*="lang-' + conID + '"]' ).html( codeHtml );"
the problem ?
If somebody could show me the good way...
The interesting code :
- $( 'img.clelangue' ).on('click',(function () {
- var dialog;
- var conID;
- // The ID is included in the parent td id
- tdID = $(this).parent('td').attr('id');
- if (/^lang-([0-9]+)$/.exec(tdID)) {
- conID = RegExp.$1;
- }
- else {
- console.log = 'nothing to select';
- }
- // We call the ajax form for the language choice
- $( "#changelanguage" ).load( "http://www.mondomaine.com/admin/index.php?module=contact&action=ajax-formlang&id=" + conID );
- dialog = $( "#changelanguage" ).dialog({
- autoOpen: true,
- height: 420,
- width: 340,
- modal: true,
- buttons: {
- Fermer: function() {
- dialog.dialog( "close" );
- },
- Enregistrer: function() {
- changeLanguage();
- }
- }
- });
- function changeLanguage() {
- // We update the database in php and get the new icone
- $.ajax({
- // the URL for the request
- url: "index.php",
- // the data to send (will be converted to a query string)
- data: {
- id: conID,
- module: 'contact',
- action: 'ajax-change_language',
- nw_lang: $( '#id_f1 input[name=nw_lang]:checked' ).attr( 'value' )
- },
- // I use POST
- type: "POST",
- // I expect back html code
- dataType : "html",
- // If the request succeeds
- // the response is passed to the function
- success: function( codeHtml ) {
- $( 'td[id*="lang-' + conID + '"]' ).html( codeHtml );
- dialog.dialog( 'close' );
- },
- // cif the request fails :
- error: function( xhr, status, errorThrown ) {
- alert( "Désolé, il y a eu une erreur dans la mise à jour !" );
- console.log( "Erreur: " + errorThrown );
- console.log( "Statut: " + status );
- console.dir( xhr );
- }
- });
- };
- }));