Hi!
item is a function, not an object, so you must call it:
linkElements.item(i).setAttribute("target", "_self")
By the way, getElementsByTagName returns HTMLCollection and you can get single item also in this way:
linkElements[i].setAttribute("target", "_self")
Finally, you incorrectly compare whether the target equals _blank. You used "=" which means you are assigning this value. You must use "==" or "===" operator. Please refer to the MDN documentation.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Strict_equality https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Equality
Corrected code and additionally the same example in ES6+ syntax
https://jsbin.com/minufujiba/1/edit?html,js,console,output