i am not really good in jquery. Is it possible, to put a variable operator to make a function work? Because of different versions of jQuery used on different Pages.
The .on-function came up in 1.7 but some sites are running with lower version and therefore i need to use the .click function instead. And i want to avoid duplicate code for each version.
For example :
$('#mySelector')(var <= 3.4) ? ".click(function()" : ".on('click', function()");
{
$( "#dialog p span" ).remove();
$( "#dialog p" ).append('<span>'+ isEncHTML(html_output)
});
Thank you all for your help.
To make it more clear:
This works with 1.7 (includes the buttons - option:
$('.delete_league, .print_league').on('click', function()
{
$( "#dialog p" ).append('<span>'+wpslm_v_script_vars.delete_league+'</span>');
$( "#dialog" ).dialog({
modal: true,
buttons:
[{
text: "OK",
click: function()
{
$( "#dialog p span" ).remove();
$(this).dialog("close");
}
}]
});
});
And this work with 1.6. If i keep the buttons-option, it throws an error.
$('.delete_league, .print_league').click(function()
{
// Just in case there is an old message hanging around
$( "#dialog p span" ).remove();
$( "#dialog p" ).append('<span>'+ isEncHTML(wpslm_v_script_vars.delete_league) +'</span>');
$( "#dialog" ).dialog({
modal: true
});
});
So, i want to make the selector-line(and the buttons-option) variable so that i can use the same code for both. Means, if i see that i am running an older version than 1.7 i ust eht .click without buttons otherwise i use .on with the buttons-option. I hope that is not too confusing now.
What is the lowest version I must support?The answer to that determines the jQuery library you end up using. In my personal opinion if you want to also write code for another application using later jQuery version not writing separate code pages islazy-codingand will in the end cost you more time debugging than the time you would spend right now writing and maintaining separate code pages. Personally, I would try to make the time savings by simply writing for the lowest jQuery library.