JavaScript How to add an attribute on load time using jquery

i have a html page in which i have a number of anchor tags i want to add rel="no follow" attribute in anchor tag if it doesn't have it on the pages whose source is starting with hyper text transfer protocol request. some of the anchor have already rel attribute. how can i achieve it through

example:-

<html>
    <body>
        <p> Here we go</p>
        <a target='_blank' href="https://www.abc.com"> a1</a>
        <a target='_blank' href="https://www.abc.com" rel="nofollow" > a2</a>
        <a target='_blank' href="https://www.abc.com">a3</a>
    </body>
</html>

i want to add rel= no follow attribute on a1 and a2 on page load time how can i achieve this

Answer:1

tri this:

var A=document.getElementsByTagName("a");
for(var i=0;i< A.length;i++)
{
    if(A[i]['rel']!="")
    {
        A[i].setAttribute("rel","Something");
    }
}
Answer:2
$("a:contains('a1'),a:contains('a2')").attr("rel","no follow");

reference contains-selector

updated

if($("a").attr("rel")=="no follow")
 {
// do stuff
  } else{// if not exist
  //do your stuff
  }
Answer:3
$(function () {// on page load time
  $('a').each(function () {// check every a element
    var text = $(this).html();// get the content
    if (text.indexOf('a1') > 0 || text.indexOf('a2') > 0) {// find a1 and a2
      $(this).attr('rel', 'no follow');// set the rel to no follow
    }
  );
});
Answer:4

This J fiddle utilizes getElementsByClassName http://jsfiddle.net/YZTpn/ This j fiddle uses getElementByID http://jsfiddle.net/9Fa89/ <script> when I print out the length of the var "x".... ...

This J fiddle utilizes getElementsByClassName http://jsfiddle.net/YZTpn/ This j fiddle uses getElementByID http://jsfiddle.net/9Fa89/ <script> when I print out the length of the var "x".... ...

  1. difference between length and width
  2. difference between length and height
  3. difference between length width and height
  4. difference between length and length() in java
  5. difference between length and depth
  6. difference between length and inseam
  7. difference between length and distance
  8. difference between length and size in java
  9. difference between length and size in c++
  10. difference between length and size in matlab
  11. difference between length and volume mascara
  12. difference between length and diameter
  13. difference between length and format in sas
  14. difference between length and count in c#
  15. difference between length and lengthb in oracle
  16. difference between length and precision in sql server
  17. difference between length and height in pediatrics
  18. difference between length and span of a bridge
  19. difference between length and magnitude of a vector
  20. difference between length and lap in swimming

I have a form that I am trying to use page two as a continuation page that will only be shown when a user checks a box. I am using Adobe Acrobat DC cloud and I tried the following code. if (this....

I have a form that I am trying to use page two as a continuation page that will only be shown when a user checks a box. I am using Adobe Acrobat DC cloud and I tried the following code. if (this....

  1. show hide page breaks in word
  2. show hide page javascript
  3. show hide page elements
  4. excel show hide page breaks
  5. jquery show hide page jumps
  6. excel show hide page number
  7. show hide tab page c#
  8. show hide div page refresh
  9. html show hide page
  10. show/hide div on page load javascript
  11. show hide div without page refresh
  12. show hide content web page
  13. power bi show hide page
  14. pdf javascript show hide page
  15. adobe acrobat show hide page
  16. jquery show hide on page load
  17. show hide div from another page

I am writing a directive which is really simple: it should wrap an input element in a div. I use transclusion for this. The problem is that it breaks ng-model for some reason. Please see this plunker ...

I am writing a directive which is really simple: it should wrap an input element in a div. I use transclusion for this. The problem is that it breaks ng-model for some reason. Please see this plunker ...

Since Node.js is (seemingly) single threaded (partially for network reasons), does it mean it can only use one CPU core at any time? Can I even get a single core server these days?

Since Node.js is (seemingly) single threaded (partially for network reasons), does it mean it can only use one CPU core at any time? Can I even get a single core server these days?