Question

This is a very specific question, so sorry if it sounds repetitive.

I have a block of code that manipulates a Wordpress's "Press This" feature that allows for quick blogging about a remote site, including copying a selection of text.

What I'm wanting to manipulate it to, is to re-blog (with credit) an entire blog post from a wordpress engine site. Wordpress.com has this feature built into their site, but if you have your own hosted site, this feature isn't present.

I have managed to select the correct DIV, along with getting the pop-up to work, however the content isn't there.

The results from :

 y = d.getElementsByClassName('entry'),

is that y = [Object Node List]

z = y.innerHTML,

the result is 'undefined'

for (var i = 0; i < y.length; ++i) {
z = z + y[i];}

the result is '[object HTMLDivElement][object HTMLDivElement]' (The result is the same as if it pulls from y.innerHTML)

I've searched extensively for help, yet can not introduce a solution to the code.

Can anybody help?

Was it helpful?

Solution

Not sure why you put a ',' at the end where a ';' should be

 y = d.getElementsByClassName('entry'),

Your problem is that getElement s ByClassName('entry') returns an array of all elements which share the class name 'entry';

If you want to access the first you should use

y = d.getElementsByClassName('entry')[0];

Or you can use for to go through all:

for(var i in d.getElementsByClassName('entry')) {
  y = d.getElementsByClassName('entry')[i];
  alert(y.innerHTML);
}

OTHER TIPS

You almost got it, try this:

var z = '';
for (var i = 0; i < y.length; ++i) {
   z = z + y[i].innerHTML;
}
alert(z); //will alert the html content of all your .entry elements
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top