skip to Main Content

I have this code:

jQuery(document).ready(function( $ ){
  var magyar = $(".lang-item-hu a").attr("href");
  $("#magyar").attr("href", magyar);
  var angol = $(".lang-item-en a").attr("href");
  $("#angol").attr("href", angol);
});

on my site. It works well on desktop Chrome, but doesn’t work on Android Chrome.

Why? And what could be the remedy for this symptom?

Question edit/update:

On my desktop I use the latest version of Chrome 95.0.4638.69 / 64 bits on Windows 11 Pro ver: 21H2

On my mobile I also use the currently updated version of Chrome: 95.0.4638.50 on Android 11, One UI-version: 3.1

There are no related error messages on the desktop version.

I don’t seem to find a debugger on Android’s Chrome…

2nd edit (the solution):

No, the browser is fine.

I just had to change the id-s to classes, like so:

jQuery(document).ready(function( $ ){
  var magyar = $(".lang-item-hu a").attr("href");
  $(".ma").attr("href", magyar);
  var angol = $(".lang-item-en a").attr("href");
  $(".an").attr("href", angol);
});

…but I don’t quite know why this worked. Anyone who knows leave an answer below. Thank you in advance!

2

Answers


  1. Chosen as BEST ANSWER

    No, the browser is fine.

    I just had to change the id-s to classes, like so:

    jQuery(document).ready(function( $ ){
      var magyar = $(".lang-item-hu a").attr("href");
      $(".ma").attr("href", magyar);
      var angol = $(".lang-item-en a").attr("href");
      $(".an").attr("href", angol);
    });
    

    ...but I don't quite know why this worked. Anyone who knows leave an answer below. Thank you in advance!


  2. One of my suggestion is try with .prop() Instead of .attr()

    jQuery(document).ready(function( $ ){
      var magyar = $(".lang-item-hu a").attr("href");
      $("#magyar").attr("href", magyar);
      var angol = $(".lang-item-en a").attr("href");
      $("#angol").attr("href", angol);
    });
    

    Changed to

    jQuery(document).ready(function( $ ){
      var magyar = $(".lang-item-hu a").prop("href");
      $("#magyar").prop("href", magyar);
      var angol = $(".lang-item-en a").prop("href");
      $("#angol").prop("href", angol);
    });
    

    More Details, pease check this link: https://stackoverflow.com/a/5876747/3073842

    Similar Question: jquery attr() not working on mobile – Android – Chrome

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search