1

I'm working with google maps and I want to change the "info window" dimensions.

The gmaps js automatically generate this section:

enter image description here

I want to target the selected section that has no id or class to identify changing it's width. Then I thought that I need to use it's child div class named "gm-style-iw" like a reference to reach the other div above.

The idea would be something like this:

div < .gm-style-iw {
 width: 220px;
}

but we know that this '<' is not possible using css.

How can I do that?

Fillype Farias
  • 532
  • 1
  • 5
  • 16

1 Answers1

2

As you are probably already aware, you'll need javascript for this to work as intended, and using jQuery's .parent()ref. method would probably be the most straight forward route to getting there.

Ref: .parent() | jQuery API Documentation

Consider the below:

jQuery('.gm-style-iw').parent().css('width','220px');

On inspecting the element, you will notice that the inline width property has been applied and is over-qualifying the external width property rule set be the selector .parent.

Code Snippet Demonstration:

jQuery('.gm-style-iw').parent().css('width','220px');
.parent {
    width: 100%;
    background: #dadada;
    padding: 5px;
    border: 1px dashed;
    box-sizing: border-box;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="parent">
  <div class="gm-style-iw"><code>gm-style-iw</code></div>
</div>

It may be better practice to consider applying a class to these elements instead. As demonstrated above, inline style rules are quite persistent and are tricky to over-qualify without depending too much on the !important declaration.

Consider the following:

jQuery('.gm-style-iw').parent().addClass('contians-child');

Using a class selector as your identifier, you can circumvent this issue which may be sparing you some grey hairs down the line or wasted hours further on into your build.

Code Snippet Demonstration:

jQuery('.gm-style-iw').parent().addClass('contians-child');
.parent {
    width: 100%;
    background: #dadada;
    padding: 5px;
    border: 1px dashed;
    box-sizing: border-box;
}

.parent.contians-child {
    width: 220px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="parent">
  <div class="gm-style-iw"><code>gm-style-iw</code></div>
</div>
UncaughtTypeError
  • 6,718
  • 2
  • 17
  • 35