Replace <head></head> in html

Discussion in 'JavaScript' started by PunitJain, Jul 27, 2022.

  1. #1
    How might I replace head tag in html with my own provided code using cheerio?
    The html structure:

    <!DOCTYPE html>
    <html>
    <head>
      <title>Example</title>
    </head>
    <body>
    
    Example html doc......
    
    </body>
    </html>
    Code (markup):

     
    PunitJain, Jul 27, 2022 IP
  2. denis bayly

    denis bayly Well-Known Member

    Messages:
    110
    Likes Received:
    29
    Best Answers:
    6
    Trophy Points:
    105
    #2
    Hi there PunitJain,

    your basic HTML document should look like this...
    
    
    
    <!DOCTYPE HTML>
    <html lang="en">
    <head>
    
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,height=device-height,initial-scale=1">
    
    <title>Untitled document</title>
    
    <link rel="stylesheet" href="screen.css" media="screen">
    
    </head>
    <body>
       
    </body>
    </html>
    
    Code (markup):
    ...PERIOD !

    coothead
     
    denis bayly, Jul 28, 2022 IP
  3. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #3
    Doesn't really help, the poor sod has been suckered into using the shit-show that is "cheerio" which is why stuff like that is (poorly) auto-generated for him. "cheerio.js" is the poster child for SPA only "f*** accessibility" asshat nonsense. A how-to guide on "screw usability and accessibility" hiding behind bald faced lies of making things "better" or "easier". Of course it's based on the shit-show that is jQuery.

    He'd be doing something like:
    
    const cheerio = require('cheerio');
    $.html();
    
    Code (markup):
    And it spits out the HTML/HEAD/BODY tags and the contents therein for him.

    Because it's jQuery f***wittery, I believe you can selector the page and simply replace its content.

    $("head").html("<title>Test</title>");

    Would replace the entire contents of the head with that title tag.

    Horrifying waste of bandwidth though, possibly insecure since $().html() is a innerHTML wrapper. But that's to be expected with the shit-show of developer ignorance, incompetence, and ineptitude that is jQuery. Worst of all it's doing something client side that generally has ZERO honking business being even touched client-side.

    I think that's something that pisses off jQ fans when I rag on it. I do know how to use it, so I know where to stick the knife and twist. And knowing it and how it works is why I hate it and cannot fathom how or why anyone is gullible enough to use it by choice.

    But to be fair I say the same about all the hot and trendy framework bullshit. Makes you work harder, not smarter.
     
    deathshadow, Aug 11, 2022 IP
    sarahk likes this.