ID attribute not being recognized

I’m new to html but in what I’ve learned so far I should be able to identify an element with an id (an id attribute) for example p id=myID> content /p>.

And I should be able to assign different styles to that id attribute, for example #italics {text-align: center; font-style: italic; color: gray;}.

Now the problem that I am having is, Komodo isn’t recognizing the name I’ve given my id attribute, it recognizes the # and everything that come between {} but it won’t apply it to the paragraph I want it to.

Is this a problem within Komodo (and is there a work around)? Or is it something I (as a new user) am doing wrong? This isn’t a serious project, I’m just playing with subjects I have learned so I want to understand how to correct it in the future.

Here is the code I’m working with, everything else seems to work fine when I upload it to a browser.

    <title>What I Read Last Week: Christmas in July</title>
        <!---***The following two are optional***--->
        <meta name="description" content="All the books I read last week."
        <meta name="author" content="Katherine"
    
    <style type="text/css">
        #myID {
             text-align: center; 
             font-style: italic; 
             color: gray;
         }
    </style>
</head>

<body>
      <h1>What I Read Last Week: Christmas in July</h1>         
      <p id="myID">This book is currently available for free with a Kindle Unlimited subscription or for purchase at your favorite online bookstore.</p>
    
    <script type="application/x-javascript"></script>        
</body>

Hi @krohrbacker88,

For future reference, this is a better question for a site like Stackoverflow as it’s a general HTML question and not pertaining to Komodo itself but I see you’re not really sure WHAT the issue is and hence you’re wondering if it’s Komodo or your code.

My best guess is that if the code you shared is the entirety of your code then you don’t have a proper HTML document. At the very least you’re missing the opening and closing <html> tags for the document. You can/should include the doctype element as well but that not being present wouldn’t cause the issue you’re seeing.

Try this:

<!DOCTYPE HTML>
<html lang="en">
<title>What I Read Last Week: Christmas in July</title>
        <!---***The following two are optional***--->
        <meta name="description" content="All the books I read last week."
        <meta name="author" content="Katherine"
    
    <style type="text/css">
        #myID {
             text-align: center; 
             font-style: italic; 
             color: red;
         }
    </style>
</head>

<body>
      <h1>What I Read Last Week: Christmas in July</h1>         
      <p id="myID">This book is currently available for free with a Kindle Unlimited subscription or for purchase at your favorite online bookstore.</p>
    
    <script type="application/x-javascript"></script>        
</body>
</html>

Also as a side note, I like to use SUPER obvious stylings when I’m trying to figure out if a css rule is working, so I set the color to red instead of gray.

  • Carey

I did include the doctype and html tags in the code but for some reason they wouldn’t appear in the final post (FYI it took me a minute to figureout how to make it an html document but it was one of the first things I worked on when setting up my file.).

In komodo my codes are all color coded (when i choose the correct ones) my problem is the #myID isn’t color coded so I’m under the impression the Komodo doesn’t recognize it (and that why it doesn’t apply it).

Is this something to do with the id name? (I tried using my own unique name for the id but then switched to examples I found when it didn’t work).

Morning @krohrbacker88,

For why you couldn’t include the DOCTYPE and <html> tags in your post here, my guess is that you didn’t wrap your code samples in code tags here. To do that you can either us back tics ( `, usually to the left of the 1 on your keyboard) or click the </> button in the menu in this edit menu box.

Can you explain how you’re arriving at “this doesn’t work”? The code I shared, which is just your code wrapped in html tags, works in Komodo and in a browser. Share a screenshot of how you’re testing.

Here’s mine working. I clicked the eye icon in the left side menu, or you can click the globe icon to open it in a more traditional browser in Komodo or a browser of your choice:

  • Carey