Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript while adding class to diffrents classes it make all the same

  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #194795
    mixafe
    Participant

    hello every body here

    when i trying to add Common class to multiple divs , each div contains link inside divs have differents classes by this way

    var setclass=”class=’common-class'”;

    $(‘p’).after(‘
    <#div ‘+setclass+’>
    <#a href=”>google<#/a>
    <#/div>
    <#div ‘+setclass+’>
    <#a href=”>facebook<#/a>
    <#/div>
    <#div ‘+setclass+’>
    <#a href=”>youtube<#/a>
    <#/div>’);

    then when i set attr value to this classes

    $(‘.class1’).attr(‘href’,’http://google.com&#8217;);
    $(‘.class2’).attr(‘href’,’http://facebook.com&#8217;);
    $(‘.class3’).attr(‘href’,’http://youtube.com&#8217;);

    now the problem is : all classes abov have href=’http://google.com&#8217;

    #194797
    Senff
    Participant

    Create a reduced test case in Codepen.io and it’ll be a lot more clear to us what’s going wrong.

    In your example above, I don’t see any code where you assign the classes “class1”, “class2” and “class3”, and I’m not sure why every DIV starts with a pound/hashtag.

Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.