javascript - Styling a ID that is generated GUID -


i'm looking style specific jqueryui dialog centers itself. problem id changes because it's generated guid in controller. how select id that's changing can center it?

this in controller

viewbag.uniqueid = guid.newguid().tostring(); 

this in cshtml

<div class="__helpitemarea" id='@string.format("div{0}", viewbag.uniqueid)' style='@(viewbag.windowwidth==null ? "" : string.format("width:{0}px;",viewbag.windowwidth)) @(viewbag.windowheight==null ? "" : string.format("height:{0}px;",viewbag.windowheight)) '> 

as can see, generates guid div id, there's no way can select specific div style it. suggestions?

since div id's dynamically generated , they're guid's , don't want use class since it's being used on other elements well. i'd suggest use jquery data attributes.

so let's assume have data attribute data-item='helparea' on div

so style these div's can use following code

$('#test').on('click', function() {     $('div[data-item="helparea"]').each(function() {         $(this).css('background-color', 'slategrey');         $(this).css('color', 'white');     }); }); 

here's sample jsfiddle. hope helps.


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -