Using javascript to alter content of a <div>

Rick Roy

How do you alter the content of a <div> using javascript when the <div> has no id or class.

I know that using something like document.getElementById('foo').innerHTML = 'Your content'; Could have been used if the <div> had an id. But in my case the content I want to alter is like this

<div unselectable="on" style="position: absolute; padding: 2px; top: 0px; left: 1px; background-color: rgb(255, 102, 0); color: white;">BOO</div>

I am partial to using document.getElementsByTagName("div")[0].innerHTML = "BOO"; to find it but how do I then proceed to modify its content? Also is this a good way to doing things?

Norlihazmey Ghazali

No there are other div too but that is the only one with that content Boo

If that case, you can find by :contains

$("div:contains('BOO')").html('hello');

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Update content of div using javascript/jquery/php

From Dev

Get content of DIV using javascript, .innerHTML not working?

From Dev

Alter data attribute using javascript

From Dev

print div or iframe content from another div using javascript

From Dev

How to make the content div scrollable without using javascript

From Dev

How to strip HTML tags from div content using Javascript/jQuery?

From Dev

How can I change the content of a div using jquery and javascript?

From Dev

How to add <li> view limit in a div content using javascript?

From Dev

How to remove content within a parent div using javascript?

From Dev

how to retrieve content within a div using regex in javascript

From Dev

How to strip HTML tags from div content using Javascript/jQuery?

From Dev

How to remove a word/string from div content using javascript

From Dev

How to add <li> view limit in a div content using javascript?

From Dev

Intercept and alter a site's javascript using greasemonkey

From Dev

Using JavaScript to alter links to current host

From Dev

Using JavaScript to alter attributes in a MVC web application

From Dev

changing the content of a nav/div with javascript

From Dev

changing the content of a nav/div with javascript

From Dev

Detecting if a content fits in in a div with Javascript

From Dev

Javascript - Change div content with onclick

From Dev

preg replace entire div or div content javascript?

From Dev

Insert Div content in Div dynamically By Javascript

From Dev

preg replace entire div or div content javascript?

From Dev

Print a div content using Jquery

From Dev

Replace div content using jQuery

From Dev

swapping div content using jquery

From Dev

Alter DIV on Checkboxes

From Dev

Copy node and alter its content

From Dev

When getenv can alter content of previously returned pointer when using glibc?

Related Related

  1. 1

    Update content of div using javascript/jquery/php

  2. 2

    Get content of DIV using javascript, .innerHTML not working?

  3. 3

    Alter data attribute using javascript

  4. 4

    print div or iframe content from another div using javascript

  5. 5

    How to make the content div scrollable without using javascript

  6. 6

    How to strip HTML tags from div content using Javascript/jQuery?

  7. 7

    How can I change the content of a div using jquery and javascript?

  8. 8

    How to add <li> view limit in a div content using javascript?

  9. 9

    How to remove content within a parent div using javascript?

  10. 10

    how to retrieve content within a div using regex in javascript

  11. 11

    How to strip HTML tags from div content using Javascript/jQuery?

  12. 12

    How to remove a word/string from div content using javascript

  13. 13

    How to add <li> view limit in a div content using javascript?

  14. 14

    Intercept and alter a site's javascript using greasemonkey

  15. 15

    Using JavaScript to alter links to current host

  16. 16

    Using JavaScript to alter attributes in a MVC web application

  17. 17

    changing the content of a nav/div with javascript

  18. 18

    changing the content of a nav/div with javascript

  19. 19

    Detecting if a content fits in in a div with Javascript

  20. 20

    Javascript - Change div content with onclick

  21. 21

    preg replace entire div or div content javascript?

  22. 22

    Insert Div content in Div dynamically By Javascript

  23. 23

    preg replace entire div or div content javascript?

  24. 24

    Print a div content using Jquery

  25. 25

    Replace div content using jQuery

  26. 26

    swapping div content using jquery

  27. 27

    Alter DIV on Checkboxes

  28. 28

    Copy node and alter its content

  29. 29

    When getenv can alter content of previously returned pointer when using glibc?

HotTag

Archive