Click here to Skip to main content
15,880,967 members
Please Sign up or sign in to vote.
2.33/5 (2 votes)
js
C#
var hy = $('.Player a.sc-player').attr('href');
                console.log(hy);

html
HTML
<div id="Over_Hidden"></div>
<div id="Wapper">
 
        <div id="Container">
          <header>
      <div id="Player">
 
        <div class="Player" ><a href="https://soundcloud.com/rapzilla/andy-mineo-stop-the-traffic" class="sc-player"></a>
          <p>hellow</p>
          <a href="" class="download_song">Download</a></div>
 
      </div>
      <!--/Player-->
    </header>
          <!--/Header-->
          {body}
 
          <div class="window_loader"></div>
        </div>
        <!--/Container-->
 
</div>
<!--/Wapper-->

the console give me undefined why ?
Posted
Updated 15-Sep-22 11:57am
v5

href=""

You need a value (link) here.
 
Share this answer
 
v2
Comments
TheSniper105 6-Jan-14 4:54am    
i updated it and the problem still any help?
It is working fine in my machine.
try with prop

JavaScript
 var hy = $('.Player a.sc-player').prop('href');
console.log(hy);
 
Share this answer
 
Comments
TheSniper105 6-Jan-14 5:51am    
what is prop?
Karthik_Mahalingam 6-Jan-14 6:34am    
like attr , this is a function in jquery..

used to read/write DOM properties
Are you certain the error is undefined href attribute value? I can't see where you are including the JQuery Library.

When I try your code (JSFiddle) I see the error Uncaught ReferenceError: $ is not defined.

The error goes away if I add the following line to your header section or, change the JSFiddle Language, Frameworks & Extensions... from "JavaScript + No-Library (pure JS)" to "JavaScript + JQuery 3.4.1" the error is resolved.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900