javascript - jQuery : how to manipulate indexes? -


should not such hard question... i'm having hard time figuring out how make operations on jquery elements, particularly indexes. teh codez:

$( "#docslider" ).css("background-image", "url(../../bundles/mypath/images/maquette/img" + $( "#selectable li" ).index( ) + (".jpg)")); 

i want make name of picture load depend on index of jquery selectable. grab index , try add 1... can't work because "+" concatenator.
i've tried parseint well, worth 0.

how transform index integer , concatenate rest of string?

thank in advance!

edit : i'm using function exists, can hardly change parameters (well, guess can't...)

i have sample of code in $(function() {}) section :

$( "#selectable" ).selectable({                 selected: function(event, ui) {                      $( "#docslider" ).css("background-image", $( "#selectable li" ).index( ) "url(../../bundles/mypath/images/maquette/img" +  + (".jpg)"));                 }});  //initalizing                 $( "#docslider" ).css("background-image",  "url(../../bundles/auraeconference/images/maquette/img" + $( "#selectable li" ).index( ) + (".jpg)")); 

use like

$( "#docslider" ).css("background-image",function(i){           return "url(../../bundles/mypath/images/maquette/img"+ (i+1)+".jpg"; });  

$.css has alternate syntax like

 .css( propertyname, function(index, value) ) 

you can make use of that.

update

this inside selectable callback, in case refers #selectable . can either use

$(this).find('li').index(ui.selected); 

or

$( "#selectable li" ).index( ui.selected ) 

so can try this

selected: function(event, ui) {        var index = $( "#selectable li" ).index( ui.selected ) + 1;      $( "#docslider" )           .css("background-image",  "url(../../bundles/mypath/images/maquette/img" + index + ".jpg)");                 }}); 

demo


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -