Cade Leadbetter
Cade Leadbetter

Reputation: 21

How to change the value of a HTML Element using a bookmarklet

I'm not very familiar with JS and I was wondering how I could edit an element of a website using a bookmarklet

I was trying to change the value of 58 in the following code:

<span class="rbx-text-navbar-right" id="nav-robux-amount">58</span>

Yet I had no luck, as I had used different information from different sites.

Could someone please help me? If I'm not being specific enough, please tell me.

Upvotes: 2

Views: 2292

Answers (1)

user2490157
user2490157

Reputation:

Set the URL of the bookmarklet to:

javascript: (code)

in order to run JavaScript in a bookmarklet. In your case, you would want

javascript:document.getElementById("nav-robux-amount").innerHTML="59";

Replace 59 with your value. Then, whenever you click the bookmark the script should activate.

Break-down

  1. javascript: indicates that we are executing a script.
  2. document.getElementById("nav-robux-amount") selects the correct element to modify.
  3. .innerHTML refers to the HTML code that is inside the element.
  4. ="59"; completes the statement by changing .innerHTML to 59.

Upvotes: 2

Related Questions