Featured post

c# - Usage of Server Side Controls in MVC Frame work -

i using asp.net 4.0 , mvc 2.0 web application. project requiremrnt have use server side control in application not possibl in noraml case. ideally want use adrotator control , datalist control. i saw few samples , references in codepleax mvc controllib howwver found less useful. can tell how utilize theese controls in asp.net application along mvc. note: please provide functionalities related adrotator , datalist controls not equivalent functionalities thanks in advace. mvc pages not use normal .net solution makes use of normal .net components impossible. a normal .net page use event driven solution call different methods service side mvc use actions , view completly different way handle things. also, mvc not use viewstate normal .net controlls require. found article discussing mixing of normal .net , mvc.

javascript - JQuery wrong ID in an inner click -


i'm trying make colorpicker. got few colorcubes class colorcube. when clicking, opens colorpicker few list items have different color. when clicking on list items should return de color/text de colorcube.

the first colorpick after document ready works. after doesnt work properly, because remembers al previous colorcube id's al other cube's change :(

is there way clear cache or that?

$('.colorcube').click(function() {     var colorcubeid = $(this).attr("id");     $('#choicecolor').show();      $(".li_color").click(function() {         var colorid = "#" + this.id;         var colorli = $(colorid).text();         $('#' + colorcubeid).text(colorli);         $('#' + colorcubeid).css({ 'background-color': '' + colorli + '' });         $('#choicecolor').hide();         savecolor();     });  }); 

you're assigning redundant click event handlers every click on colorcube. should assign handlers once.

it seems you're doing in order reference id of colorcube clicked. use variable instead track clicked.

var $currentcube,     $choicecolor = $('#choicecolor');  $('.colorcube').click(function() {     $currentcube = $(this);     $choicecolor.show(); });  $(".li_color").click(function() {     var colorli = $(this).text();     $currentcube.text(colorli)                 .css({ 'background-color': colorli });     $choicecolor.hide();     savecolor(); }); 

i made number of changes well.

instead of referencing id of current color cube, i'm referencing actual element wrapped in jquery object, can call methods on directly.

this code:

var colorid = "#" + this.id; var colorli = $(colorid).text(); 

...is more complex needed, since can do:

var colorli = $(this).text(); 

...where this <li> clicked.

you don't need:

'' + colorli + '' 

because colorli string. do

.css({ 'background-color': colorli }) 

as @Šime vidas noted, should cache $('#choicecolor'); you're not selecting dom.

var $currentcube,     $choicecolor = $('#choicecolor'); 

i used chaining on line. jquery don't need separate function calls against same jquery object. can chained together.

$currentcube.text(colorli)             .css({ 'background-color': colorli }); 

Comments

Popular posts from this blog

c# - Usage of Server Side Controls in MVC Frame work -

cocoa - Nesting arrays into NSDictionary object (Objective-C) -

ios - Very simple iPhone App crashes on UILabel settext -