3

I'm trying to get Chrome inspector to show me the class names and their properties used in a jquery plug-in so I can overwrite and adjust them like I want. However Chrome inspector css window doesn't show it.

I am using a plugin which shows a popup of list items when I click on a textbox. See jsfiddle

$('#example-1').timeselect({
   'step': 15,
    autocompleteSettings: {
        autoFocus: true
    }
});

I want to change the highlighted row background colour and text size from what currently is there as shown in the following screenshot

enter image description here

I read in this answer to see the hover css in Chrome inspector I need to check the .hov style in the window.

It does not matter what element state I set it to. The Chrome css window will not show me the css for the 2 properties I am trying to change i.e. highlighted row font size and background colour. It doesn't show me that gray colour in the window at all. It only allows me to change the static font size of the textbox, not the text size of when the textbox is clicked and the hover is active.

I had a look at the javascript code on GitHub for the plugin. There is no reference. There is no reference to any css or style being applied to it.

Summary of the answer given below:

  1. The jquery plugin creates html on DOM ready. Locate the created html in Chrome inspector.

  2. Use the inspector to highlight the relevant html created element and take note of the css class name that dynamically gets inserted in the html when I visually highlight a row.

  3. In Chrome's css panel window click the + icon and add the class name identified in step 2.

  4. View and adjust the css properties for the specific class

Community
  • 1
  • 1
dfmetro
  • 4,462
  • 8
  • 39
  • 65
  • That's with javascript. When you hover an item, javascript adds a class (like `element-hover` or something similar) and it changes the style. That's not the pseudo-state `:hover`, it's a normal classname – Marcos Pérez Gude May 09 '16 at 11:14
  • How do I use my browser tools to determine what class is being added via javascript. Also the GitHub source shows no references to any class names or styles. – dfmetro May 09 '16 at 11:37

1 Answers1

1

In the fiddle, you can inspect the input box (where you click to enter text) and watch the HTML change when you click on and off. If you don't see the elements highlight when they open and close (which usually means that element is changing, like the style of display:none; to block), then you can start mousing over the elements in the inspector.

when you mouse over the elements in the inspector, you'll see the block you want light up. Sometimes the block you want is contained in a bigger block, so you'll have to Just traverse this block (using the black arrow next to it to open the element)

You're looking for <ul class="ui-autocomplete ui-front ui-menu ui-widget ui-widget-content" id="ui-id-1"... This element houses all of the select options.

In the picture below, the way I found the block was to inspect the actual input for "basic examples". This showed me the fully traversed input with an id #example-1. Then since I clicked somewhere else, the actual options were hidden, so I clicked on the input again to open them up and I noticed something changed in the inspector. So, I just moved my mouse over the elements in the inspector while the options box was open. I saw that the div (highlighted in gray in the inspector) was the containing box for the options, then I just traversed from there. enter image description here

TLDR; You're going to change the backgrounds of .ui-menu-item

ntgCleaner
  • 5,865
  • 9
  • 48
  • 86
  • Thanks for your answer. `ui-menu-item` is each item in the list. When I move my mouse over it I see that the highlight row is `ui-state-focus`. This is the class that contains that gray background. How do I get this css class to show in the Chrome inspector window so I can change it there to preview? Can Chrome inspector do this? It's like I cannot view the focus event for the element ui-menu-item – dfmetro May 09 '16 at 12:12
  • @devc2, Usually at the bottom of the CSS panel in the inspector has `:hover, :before, :after` pseudo elements. I'm not so sure about hover. But, basically, the way this is working is; jQuery is using `.focus` to change the class. Since we can't see the class when it's on focus, we'll have to search the CSS. In the CSS panel, you'll see the main class for that element. On the top right of that class you'll see which CSS is controlling it. In this case it's `jquery-ui.css`. Right click on `jquery-ui.css` and then click "open in new tab". From there, you can search for `ui-state-focus`. – ntgCleaner May 09 '16 at 12:22
  • @devc2, When you're inside the CSS (after open in new tab) just tap Ctrl + F (or cmd + F on mac) to search within the page. and search for `ui-state-focus`. Hit the "next" arrow until you find the one you may be looking for. It may take more sloothing, but you'll find one that has a background-image. This is the one you can override. – ntgCleaner May 09 '16 at 12:23
  • @devc2, If you want to try out your changes, go back to the inspector. Since we can't see the `ui-state-focus`, you can click on the "+" on the top right of the CSS panel. This will add a new blank style. Just name it `.ui-state-focus` (you may have to prepend more parent CSS for this to work) and then add your style inside of it. – ntgCleaner May 09 '16 at 12:25
  • Thanks. Adding `ui-state-focus` in the css panel made it show. – dfmetro May 09 '16 at 13:56
  • @devc2, You got it! Glad I could help! – ntgCleaner May 09 '16 at 14:33