Html tag with inline js

Hello all. try to add inline js to a button. So that on click it will add an attribute to it. it doesn’t seem to work but have similiar code w/an alert that does. Was wondering how I could make it work? thx
hmm. seems to work actually.
how do i delete this pen?

Not using JQuery, per se, I was able to get it to work like this:

<button onclick="this.innerHTML='Ouch';">
  this
</button>

Old-fashioned Javascript.

Thank you ParkinT

Why - jumbling HTML and JavaScript together has never been a good idea and has been completely unnecessary since Netscape 4 died - you aren’t still trying to support that browser are you?

1 Like

Why yes! How’d you guess?!? And IE3.

No, that’d be horrible. But we are working with some hybrid older code and that it is where it is going.
Although it is one of my project to clean it up in the future.
:smile:

You could start the cleanup by placing the modifications in a script tag at the bottom of the page instead of inline. That would then make them easier to move to a separate file when you clean it up properly.

been there, done that. still working on it

Fortunately though, when all that nasty “JavaScript” has
been removed from the markup, we find that “BootStrap”

<body class="home page page-id-4401 page-template page-template-page-home page-template-page-home-php">

…and that other coding godsend “WordPress”

<li id="menu-item-6" class="menu-item menu-item-type-custom menu-item-object-custom current-menu-item current_page_item menu-item-6 active">

… have impressively stepped up to the plate to make an
even better mess of the our HTML :cold_sweat:

coothead

1 Like

Yes, that caters to the many “I don’t know how to craft CSS selectors” users.

True, there are times when more than a single class value are needed, but not that often.

Why put it off? You’re working with it now. Now seems like the time to do it correctly rather than wasting time doing it incorrectly.

1 Like

It can come in useful if you use one class to set the colour of an element and a different class to set its size.

Many years ago I wrote a piano chord script in JavaScript and used CSS to style divs to display a piano keyboard where I used several classes on each div to define how it should look - no images were used in the creation of the piano keyboard - just divs with multiple classes attached. Rather an obscure use of CSS that shows how multiple classes on the one tag can be useful for unusual situations.

2 Likes

oh i don’t know about that…I like wp. Bootstrap is indeed a bit too wordy but they booth have their uses.
There are usually pros and cons to everything. Except republicans/teabaggers or libertarians. Nothing good there.

It’s complicated. very old code ties together multiple pages that are a tad brittle. So step lightly like on a mine field and am developing a cleaned up version locally. when it is ready I’ll xfr

The same could be applied to toilet paper,
but I really wouldn’t wish to see a roll of it it
prominently positioned on my dining table. :mask:

coothead

Well, not sure about that analogy but personally i use wp quite a bit and have come to appreciate it. And for bootstrap it is at least good to have a nodding aquaintance.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.