0

I'm trying to resize a panel using JavaScript to fit a small image into a panel, and struggling badly.

It's within the bold:

<body id="visCinemaTransRefund"><br>
<div id="content"><br>
<ul class="PayPanel" id="paymentDetails"><br>

Here's the CSS that needs modifying:

visCinemaTransRefund .PayPanel { width: 435px; }

How would I be able to modify with width of this panel?

I've also got a form I'm trying to resize within CSS:

visCinemaTransRefund FORM (width: 1005px;)
1

5 Answers 5

1
document.getElementById('paymentDetails').style.width = '1000px';
Sign up to request clarification or add additional context in comments.

2 Comments

This works perfectly, thank you very much. For the form I used: document.getElementById('form').style.width = '1005px';
@MichaelMorgan Is the form ID or HTML tag?
1

Have you tried using:

document.getElementById("paymentDetails").getElementsByClassName("PayPanel")[0].style.width="1000px"

Remember: getElementsByClassName return an array of elements, so using [0] you are indexing first element (and, of course, the only one).

Since getElementsById return a single elements, getElementsByClassName could be useless.

Comments

0

If you want to do this using CSS class :

HTML:

<div id="myDiv" class="medium"></div>
<button id="btn">Click me</button>

CSS:

#myDiv {
    background-color: gray;
}

.medium {
       height: 50px;
       width: 50px;
}

.big {
       height: 100px;
       width: 100px;
}

JS:

document.getElementById("btn").onclick = function() {
    var element = document.getElementById("myDiv"); // or document.getElementsByClassName("className")

    if (element.className == "medium") {
        document.getElementById("myDiv").className = "big";
    } else {
        document.getElementById("myDiv").className = "medium";
    }
};

JSFIDDLE

Comments

0

Use the following code to change the width of tags by accessing HTML element from the DOM using getElement functions and setting width to it using setAttribute javaScript function.

document.getElementById("paymentDetails").setAttribute("style","width:500px;");
document.getElementById("visCinemaTransRefund").getElementsByTagName("form")[0].setAttribute("style","width:1000px;");

2 Comments

It would be better if you explained the piece of code as well.
@CodingMash Explanation added :)
0

Using JavaScript:

document.getElementById('paymentDetails').style.width = '1000px';

Using JQuery:

$("paymentDetails").width(1000);

$("paymentDetails").css("width","1000px");

Comments

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.