2

I'm attempting to create a jQuery function that will automatically resize a particular image to it's parent's width. If it's relevant this is for vbulletin 4.2.0

Here's the relevant (simplified) code:

<head>
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
    <script type="text/javascript">

        $(document).ready(function () {
        var newWidth = $('.floatcontainer.doc_header').css("width");
        $('.logo-image').css("width", newWidth);

        });
    </script>
</head>

<div class="floatcontainer.doc_header" style="width: 90%; height: 200px;">
    <img class=".logo-image" src="/img/headerimg.jpg"/> //the image is naturally 1092x200
</div>

SOLVED! I finally figured out where to go to edit the css for this picture, so I didn't need to do it with jQuery. Not exactly the solution I was looking for, but hey - who's complaining!

Thanks for your help!

SoWizardly
  • 387
  • 1
  • 6
  • 16
  • 3
    don't add dots in the class names. Dots are used as css selectors for selecting elements with class. i.e if you have an element with class="some_name", then you can select that element via the css selector .some_name – fredrik Dec 14 '12 at 21:58

2 Answers2

3

Missing proper class selector

 $('.floatcontainer doc_header')
                    ^--- Missing the class selector 

supposed to be

 $('.floatcontainer.doc_header')  // Make sure there is no space
                   ^----

Check Fiddle

UPDATE

I see what the problem is

<img class=".logo-image"

Has a class with a dot in it ..

So the correct selector for that is

$('.\\.logo-image')

AND NOT

$('.logo-image')

That is the reason it was not finding the specific Image

UPDATED FIDDLE

If you want it to work with the selector you have specified then change your class in HTML to

<img class="logo-image" ^--- No dot Here .. So selector is $('.logo-image')

<img class=".logo-image" ^--- dot present .. So selector is $('.\\.logo-image')

Sushanth --
  • 55,259
  • 9
  • 66
  • 105
0

Try this:

$('.logo-image').width($('.floatcontainer.doc_header').width());

Also you shouldnt be using dots in your element classes!

Possible also to change the css instead:

 .logo-image { width: 100%; }
jtheman
  • 7,421
  • 3
  • 28
  • 39