Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

JavaScript How to access link href value

System32

Active Coder
Here is the HTML:
HTML:
<div class="container-imgs-list" style="max-height: 500px; margin-top: 8px" id="imageList">
   <div class="image_column">
      <div class="image_item" id="0i0" style="aspect-ratio: 1 / 1;">
         <img src="https://2img.net/280x/cdn4.iconfinder.com/data/icons/free-color-christmas-icons/24/Christmas_Tree-256.png" loading="lazy" height="250" width="250" alt="bb codde table">
         <a href="/t4-bb-codde-table#10" class="text_overlay" style="width: 100%; width: -moz-available; width: -webkit-fill-available; width: fill-available;">
            <div class="innerTitle">
               <div title="bb codde table" style="min-width: 234px;">bb codde table&nbsp;&nbsp;</div>
            </div>
         </a>
      </div>
   </div>
   <div class="image_column">
      <div class="image_item" id="0i1" style="aspect-ratio: 0.705882 / 1;">
         <img src="https://2img.net/280x/i.pinimg.com/564x/94/5f/d8/945fd8c23dfe0379edce0988d054c1dc.jpg" loading="lazy" height="355" width="250" alt="[solved]nbeka nova tema">
         <a href="/t2-solvednbeka-nova-tema#9" class="text_overlay" style="width: 100%; width: -moz-available; width: -webkit-fill-available; width: fill-available;">
            <div class="innerTitle">
               <div title="[solved]nbeka nova tema" style="min-width: 234px;">[solved]nbeka nova tema&nbsp;&nbsp;</div>
            </div>
         </a>
      </div>
   </div>
   <div class="image_column"></div>
   <div class="image_column"></div>
</div>

Now, I want to get href values of links there.
 
Last edited:
Yeah, I can see that by myself. I need code to aquire that. :x3:
Haha yes, of course. But still I could not resist 😁

Both of your anchors have class text_overlay. Assuming this is the rule, and no other elements have this class too, this code

JavaScript:
var hrefs = [];
for (const a of document.getElementsByClassName("text_overlay"))
{
    hrefs.push(a.href);
}

gives you an array with all the href values. HTH.
 
Haha yes, of course. But still I could not resist 😁

Both of your anchors have class text_overlay. Assuming this is the rule, and no other elements have this class too, this code

JavaScript:
var hrefs = [];
for (const a of document.getElementsByClassName("text_overlay"))
{
    hrefs.push(a.href);
}

gives you an array with all the href values. HTH.
i got an empty array. With this code i know how many images there are, but no idea how to gain href of links

JavaScript:
$(document).ready(function(){
let children = $("#imageList .image_column").length; // Total number of images in shared images

  console.log(hrefs);
  });
 
An empty array, that reeks of an error. Did you check the console log ? It works for me, see attached image. My html is your code verbatim, with necessary surrounding tags added plus a few lines of JS.

No idea about your jQuery - I don't use it - or what you mean with "images in shared images".

General remarks - why don't you use a <table> instead of this circus of <div>'s ? And why do you use two <div>'s to define the text of an anchor, instead of just using <a href="xxx">bb codde table</a> ?

a.jpg
 
Oh ok. Maybe forumotion programmers don't know about HTML tables... Or maybe they do but they just love to use as many div's as possible 😅
Your console output does not show anything interesting - nothing that pertains to the code you showed or the java script that you added, except the confirmation that two children were found by your jQuery code. I hope that's not all the info jQuery can provide...
And I really don't know why my JS does not work for you like it does for me.
 
Oh ok. Maybe forumotion programmers don't know about HTML tables... Or maybe they do but they just love to use as many div's as possible 😅
Your console output does not show anything interesting - nothing that pertains to the code you showed or the java script that you added, except the confirmation that two children were found by your jQuery code. I hope that's not all the info jQuery can provide...
And I really don't know why my JS does not work for you like it does for me.
They used tables on eariler versions they modified such as phpBB2, phpBB3, PunBB, Invision. But as new versions came, they used divs. :D
 

New Threads

Buy us a coffee!

Back
Top Bottom