0

Still a Newbie using Javascript. I know something's wrong with my function code. I just can't restructure it well.

HTML:

<div class="column">
    <img src="http://placehold.it/200x200&text=IMG1" onerror="imgError(this);" />
</div>
<div class="column">
    <img src="httzp://placehold.it/200x200&text=IMG2" onerror="imgError(this);" />
</div>

JS:

function imgError(image) {
    image.onerror = "";
    parent('div.column').image.css('border','5px solid red');
    return true;
}

JSFiddle Link

Thanks in advance.

Bhushan Kawadkar
  • 28,279
  • 5
  • 35
  • 57
Philcyb
  • 165
  • 2
  • 13
  • http://jsfiddle.net/philcyb/c0wfe7wv/1/ ooops. sorry. incomplete. here's the updated one. forgot to save. – Philcyb Sep 24 '14 at 05:08
  • not able to understand plz explain what do you want actually??? – Kartikeya Khosla Sep 24 '14 at 05:10
  • ok. in the second DIV i simply inserted "Z" in the http so that the image source will have an error. And once there is an error within that image inside that particular DIV, I want to style the DIV. thanks again. – Philcyb Sep 24 '14 at 05:11
  • @Flopet17 - can you save it and share your jsfiddle which is updated? to Kat - i just added an explanation. – Philcyb Sep 24 '14 at 05:13

1 Answers1

2

Try This:

function imgError(image) {
    $(image).parent('div.column').css('border','5px solid red');
}

DEMO

Kartikeya Khosla
  • 18,743
  • 8
  • 43
  • 69
  • 1
    @Philcyb hey, If this answer is use full to you, Mark it as a answer. – CJ Ramki Sep 24 '14 at 05:29
  • @Kartikeya - sure. just one more added question. since I need to make this work in IE8, .remove() does not work. is there a Javascript replacement instead of .remove()? what i mean is, not using the $. just pure javascript. – Philcyb Sep 24 '14 at 07:28
  • @Philcyb..jquery versions below 2.x i.e. 1.11 and below perfectly works with ie8 also and you can easily use `.remove()` to remove dom elements but if you only need javascript then follow these links http://stackoverflow.com/questions/8830839/javascript-dom-remove-element and http://stackoverflow.com/questions/3387427/javascript-remove-element-by-id and if there is another question you want to ask then put a new question on SO and we will solve it .. try to refrain asking question in comments section..now mark this answer as accepted so that it will help others also..thanks... – Kartikeya Khosla Sep 24 '14 at 07:51