Adding javascript to style an element

Home Forums Plugin Integration Adding javascript to style an element

This topic is: resolved

This topic contains 2 replies, has 2 voices, and was last updated by  pitamaria 3 years, 7 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #3576

    pitamaria
    Participant

    I’m trying to style a particular element that, due to the construction of the plugin that houses it, can only be controlled via its name attribute. According to some web research, the following snippet will get the job done.

    var v_obj = document.getElementsByName('Vaccinations');
    v_obj.setAttribute('style','border-color:red;background:none');

    This snippet needs to appear in my child theme’s head, right? And the best way to do that is via my functions.php, right?

    I only need it to run in one or two specific places, identifiable by a page class (e.g. body class=”page-id-80″) or element id (e.g. form id=”form-10-1376150103″).

    Any help I could get to make this snippet run successfully would be greatly appreciated. Thanks in advance.

    #3578

    Scott Nix
    Moderator

    Gist – https://gist.github.com/scottnix/6201993

    The conditional of is_page ( 80 ) makes it so it will only run on that specific page. If you needed it to run on more pages, just comma seperate them is_page ( 80, 81 )

    #3579

    pitamaria
    Participant

    @scott: You’ve helped me before and I so appreciate it.

    Your snippet didn’t work, unfortunately, but I attribute that to the script, not your syntax. Regardless, I found a different solution so I’m setting this topic as “resolved”.

    For those curious, the solution I’m settling for is detailed here: http://stackoverflow.com/questions/5468766/can-i-apply-a-css-style-to-an-element-name. It’s admittedly buggy in many browsers but I’m gonna roll the dice.

Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Adding javascript to style an element’ is closed to new replies.