tags:

views:

66

answers:

3

Hi,

I have a multiple div almost more than 50 and there are some div with class "holiday"

Example:

<div class="fc-event fc-event-vert fc-corner-top fc-corner-bottom **holiday**" style="position: absolute; z-index: 8; top: 0px; left: 61px; width: 71px; height: 40px;">content</div>

I am trying to identify this div in jquery and modify the width from 71 to 80 px ..

i tried

$('div.holiday') it return object but when i try $('div.holiday').attr('width') it return undefined...

Can someone help me in this how i can resolve this issue.

Regards Priti

+2  A: 

**holiday** is not a valid class name, it needs to be just holiday then the code you have will work.

You can then do this as a shortcut:

$('div.holiday').width(80);
Nick Craver
typo error ... I tried to highlight it actually... in code it is without "**"
@pritisolanki - In that case use `.width()` to get and `.width(80)` to set.
Nick Craver
$('div.fc-holiday').width() return null
@pritisolanki - I don't see a `fc-holiday` class anywhere, should be just `div.holiday`
Nick Craver
when I try .width() method for other div it works but with some reason it is not working for div with class holiday...fc-agenda-body is parent div on which holiday div is floating....can this be reason width() method is not working?
@pritisolanki - The words "not working" are hardly ever useful by themselves in programming, what isn't it doing?
Nick Craver
It is not displaying the width for divs which are sharing class name = holiday.when i try the width() method for another div "fc-agenda-body" it return the width.now the only difference I can find is fc-agenda-body is parent div and holiday divs are floating on it.As I am new to these floating div I have no idea whether I will be able to access them or not.. If I am then width() should return me the width of holiday div ???
@pritisolanki - Is it visible when floating or hidden?
Nick Craver
yes it is visible when floating... I tried attaching a image...
For example: Please go to this link ... http://arshaw.com/fullcalendar/ - Click on Week view.... Now, you can see those blue color slots.... I am trying to access those..
@pritisolanki - I can't find any elements with class of holiday on any of those pages. For all the events though if you just want a consistent size, this works: `$('div.fc-event').width(80)`
Nick Craver
It's a example to show you whether those divs are visibile or not.. Please refer - "class="fc-event fc-event-vert fc-corner-top fc-corner-bottom holiday" All div share class "fc-event" but we assign special class to some div i.e. holiday . I just want to pick div with class assigned holiday ... not all..
+3  A: 

.attr will return actual tag attributes ... as when it is defined like <div .... width="50px">

you need to use the css width $('div.holiday').css('width') which will return 71px

alternatively there is the width method $('div.holiday').width() which will return 71

To change the value you can again use two ways

$('div.holiday').css('width','80px');

or

$('div.holiday').width(80);

Gaby
As width is defined in "style" attribute in div so, I am trying to read it via css. Still I tried $('div.holiday').css('width') and it is returning undefinedAny more suggestion or correction
There's no reason why it shouldn't work. The 'style' attribute is merely an inline variant of standard CSS. Where are you loading the jQuery on the page?
dclowd9901
it is not working for holiday div .. I am new to these div and floating div concept and I myself not able to understand this behavior..
are you sure the class is `holiday` ? or is it `fc-holiday` like you mentioned somewhere ?
Gaby
gaby it's holiday..
@pritisolanki, on the link you gave in your comment, no element has a `holiday` class assigned... they all have a `fc-event` class though, maybe you should target that..
Gaby
can you please explain me one thing,<div style="position: relative; overflow: hidden;"><table></table><div class="fc-event holiday"></div></div>can I access holiday div now? as holiday event is with in div where overflow is set to hidden. ?as when i tried alerting $(div.holiday).is(:hidden) it say "false" !!
`:ishidden` is irrelevant to overflow .. (look at http://api.jquery.com/hidden-selector/ ). Have a look at http://jsbin.com/otucu5/edit for an example i made that demonstrates that you can always access the width of an element.. ( *play around with the top property of the holiday class to move the div outside of the wrapper* )
Gaby
Thanks Gaby.. this was very useful... let me try what else i am doing wrong !!
Gaby... can you please check the 'http://jsbin.com/otucu5/edit' url I have modified something there ... if you see $('#preview').css('z-index') i am trying to alert z-index for preview but it is saying "undefined" ..I am using firebug and can see the same issue here as well... Please give a look..
you need to click the new revision button to share changes with others... i still see my version of the code..
Gaby
please try again
@ pritisolanki , there is no element with id `preview` in that sample..
Gaby
http://www.freeimagehosting.net/image.php?e018839437.jpg please see this image you will be able to see div with "preview" so ... in firebug if see you will be able to see... do you know why that div is "dimmed" compare to other divs????...
@pritisolanki, the `#preview` div there is from the jsbin site, and you do not have access to it, because it is out of scope.. but that does not affect your own site where you have full access to all the DOM. If you run the `alert( $('#preview').css('z-index') );` from the firebug console you will see that it works, because it has scope to the whole page..
Gaby
Yes in firebug when i tried it worked as you said !! If i see my code my holiday divs are also showing the same dimness as preview div here in firebug... but then I should be able to access those div.. what is the mystery in css and javascript world !! I have no questions because I simply don't understand what is it now..I heartily appreciate your patience Gaby with me...
A: 

It may be that there is an error in the HTML. Edit the css to see if the DIV is correctly defined

Nigel Francois