Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
122
rated 0 times [  124] [ 2]  / answers: 1 / hits: 39277  / 12 Years ago, tue, july 3, 2012, 12:00:00

I am trying to generate an MD5 check-sum of every element on a page that has the <h2> tag, then display the values as a popup.



The code I have already should get each <h2> element, I just need to get the actual value of each one.



var ghead = document.getElementsByTagName('h2');

for (i=0; i<ghead.length; i++) {
var gh = ghead[i];
var ts = gh.toString();
var ms = b64_md5(ts);
alert(ts);
alert(ms);
}


The usage of b64_md5(ts) basically is what converts the ts variable into the MD5 value. However, the ts variable is the ID or name of the Type of Element, not the Element's value itself.



Also, if I wanted to make a cookie that has two values stored in it, a name and a checksum, could I use gh.innerText; to set the unique name, as I have had issues with using this method so far.


More From » html

 Answers
11

You can use the innerHTML property to get the HTML contents of an element:



var ts = gh.innerHTML;


Note that h2 elements (and most other elements) don't have a value. Only elements that behave as form controls have a value property (e.g. the input element).


[#84500] Monday, July 2, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
chase

Total Points: 78
Total Questions: 106
Total Answers: 93

Location: Comoros
Member since Tue, Mar 14, 2023
1 Year ago
chase questions
Thu, Mar 31, 22, 00:00, 2 Years ago
Thu, Jul 1, 21, 00:00, 3 Years ago
Sat, Dec 12, 20, 00:00, 4 Years ago
Mon, Sep 14, 20, 00:00, 4 Years ago
;