Results 1 to 6 of 6

Thread: how to target image with css

  1. #1
    Join Date
    May 2014
    Posts
    203
    Thanks
    28
    Thanked 5 Times in 5 Posts

    Default how to target image with css

    i have a javascript that calls an image. is there a way with css to change the parameters (width and height) of that image if the only place the image is mentioned is inside the javascript?

    p.s. wasn't sure if this was a css question or a javascript question. lol

  2. #2
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    You'd target it the same way as if the image was in HTML - Apply a class to the image, then use that class as a selector in the stylesheet.
    Focus on Function Web Design
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps

  3. #3
    Join Date
    May 2014
    Posts
    203
    Thanks
    28
    Thanked 5 Times in 5 Posts

    Default

    but the image is only being called inside the javascript. how do i apply a css class inside a javascript? these are two different languages

  4. #4
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    You can apply a class in JavaScript in a few ways;

    Code:
    document.getElementById("myelement").classList.add("myclass"); /* IE10+ http://caniuse.com/#feat=classlist */
    Code:
    document.getElementById("myelement").className += " myclass"; /* note the space in case there are other classes */
    with jQuery;
    Code:
    $("#myelement").addClass("myclass");
    Focus on Function Web Design
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps

  5. The Following 2 Users Say Thank You to Beverleyh For This Useful Post:

    jundo12 (01-23-2016),Ripsaw (01-22-2016)

  6. #5
    Join Date
    May 2014
    Posts
    203
    Thanks
    28
    Thanked 5 Times in 5 Posts

    Default

    thanks bev!

  7. #6
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    You're welcome
    Focus on Function Web Design
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps

Similar Threads

  1. target image placement
    By cway in forum Dynamic Drive scripts help
    Replies: 8
    Last Post: 11-08-2010, 04:41 PM
  2. Random image - link target
    By matt punga in forum JavaScript
    Replies: 8
    Last Post: 05-09-2008, 04:27 PM
  3. image --> onclick --> href to target
    By Francisco Dias in forum JavaScript
    Replies: 1
    Last Post: 12-04-2007, 05:48 PM
  4. Target a page and load target iframe
    By deneb87 in forum HTML
    Replies: 3
    Last Post: 05-26-2007, 08:37 AM
  5. Replies: 0
    Last Post: 04-25-2007, 07:13 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •