1

solved with @jcubic code: "To get the value use $("#expand"+idxpand).css('overflow');"


I want to get the property of overflow.

   alert(document.getElementById("expand"+idxpand).style.overflow);

Onclick if div overflow is set to hidden, expand the content . If is not set to hidden, set to overflow:hidde.

 $('<div id="expand'+xpndid+'" style="position: relative;overflow-y: hidden;
max-height: 255px;"></div><a href="#" onclick="idxpand='+xpndid+';
expandimg();" >view photo</a>').prependTo('#mybox').hide().fadeIn('slow');
xpndid++; 
function expandimg(){
if (document.getElementById("expand"+idxpand).style.overflow == 'hidden')
    {
    //do things}
 else{
//set to hidden
}
}

I am unable to get the property. On alert I get empty value. Any idea?

5
  • probably ther style is applied through a stylesheet and is not added on the element's style property, use this stackoverflow.com/a/2953122/3591273 Commented May 2, 2015 at 12:23
  • Maybe because you use an ' in your id. Thought you have to Note it like \' Commented May 2, 2015 at 12:28
  • 1
    Try to use jQuery $("#expand"+idxpand).css('overflow', 'hidden') Commented May 2, 2015 at 12:30
  • @jcubic I want to get the property, not to set. @ Nikos for alert(css(document.getElementById("expand0"))); in console log I get this error :Uncaught ReferenceError: css is not defined Commented May 2, 2015 at 12:46
  • To get the value use $("#expand"+idxpand).css('overflow'); Commented May 2, 2015 at 12:47

1 Answer 1

1

I think that you get the wrong element, try:

<a href="#" onclick="idxpand='\'+xpndid+\'';expandimg();" >view photo</a>
Sign up to request clarification or add additional context in comments.

5 Comments

No need to escape quotes.
@CCA You have to because it's a string inside single quote.
And in this case? --- $('<div id="expand'+xpndid+'" style="position: relative;overflow-y: hidden; max-height: 255px;"></div><a href="#" onclick="idxpand='+xpndid+';expandimg();" >view photo</a>').prependTo('#mybox').hide().fadeIn('slow'); xpndid++;
@CCD Thats completelly different code, it's not html anymore with id where you have single quote.
True, I will improve my question. Your code from the comment need to be in your answer "To get the value use $("#expand"+idxpand).css('overflow');" Thanks!!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.