Forum Moderators: open

Message Too Old, No Replies

jQuery causes glitch with <input .> <label .>

         

csdude55

10:08 am on Mar 11, 2017 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I've been working on this one for 2 days, and I've finally got the issue isolated! And I don't think it's on my end.

Here's the code I have it narrowed down to:

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquerymobile/1.4.5/jquery.mobile.min.js"></script>
</head>

<body>

<input type="radio" id="1">
<label for="1">One</label>

<input type="radio" id="2">
<label for="2">Two</label>

<input type="radio" id="3">
<label for="3">Three</label>

<input type="radio" id="4">
<label for="4">Four</label>

</body>
</html>


In my live code, I only load jquery.mobile.min.js if it's a mobile device. So what I discovered is that, on desktop, the <input> and <label> tags all load as display: inline, as expected. But on mobile, they were loading as display: block.

(I didn't technically confirm that this is the exact CSS, but I know that on desktop they were all in a nice little horizontal row, while on my mobile the first label and input were inline, then the second set of label and input was on the next line, and so on.)

Even more confusing, on desktop they loaded with the input first, as expected; eg, 0 One. But on mobile, they reversed for some reason; eg, One 0.

I finally discovered that I could remove either one of the jQuery libraries, and they would load inline and in order as expected (which is what was happening on my desktop since I wasn't loading jquery.mobile, it just took forever to figure that out).

I'm really just now getting my feet wet with jQuery, so I guess I have 2 questions:

1. Am I correct that I need both of these? I'm pretty sure that I'll just be using jquery.mobile.min.js so that the user can swipe right / left for mobile navigation.

2. Assuming that I do need both, what's the workaround to make these load inline and in the order they're coded? I realize that I can add style="float:left" to each of them and force them to be inline, but it still shows the <input> and <label> in reverse order so that's not a perfect fix.

TIA!

NickMNS

5:59 pm on Mar 11, 2017 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I don't think you are using the correct version of JQuery. According to the jQurey Mobile site: [jquerymobile.com...]

you should use the following CDN links:
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css" />
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>

Note that jQuery is 1.11.1 as opposed to 2.2.0. So there may be a compatibility issue with the mobile package.

csdude55

9:06 pm on Mar 11, 2017 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Good thought! I assumed that going to an older version might cause compatibility issues, performance issues, maybe security issues. Google shows that there's a newer version than I was using, though:

[developers.google.com...]

Stepping up to version 3.1.1 fixed the immediate problem, too :) But apparently 3.x removes a few other features that I was using, too, so I guess I still have to do a little extra work to use 3.x.

Thanks, Nick!

csdude55

9:15 pm on Mar 11, 2017 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



For those reading, here's the list of changes in the 3.x release:

[blog.jquery.com...]

The loss I immediately noticed was .load.

NickMNS

9:52 pm on Mar 11, 2017 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Actually going to 3.1.1 was my first thought, I am using it on my current project but I am not using jQuery for styling and mobile. So I wasn't sure about the impact of the version change.
I am using Bootsrap v4 for styling.

csdude55

1:29 am on Mar 17, 2017 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Note: I wish I could change the subject of this thread to something like jQuery glitches between versions, then we could update with other glitches.

This isn't exactly the same as the topic of the thread, but it's close enough that I thought it would be better to just update you guys here.

I discovered today that, after updating jQuery to 3.1.1, now the "swipeleft" event is no longer recognized! It worked in 2.2.0, but not 3.1.1. After some digging, this is a known incompatability between 3.x and jQuery Mobile 1.4.x.

Here's the code I was using:

<script src="//ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquerymobile/1.4.5/jquery.mobile.min.js"></script>

// I tried both of these functions separately
$(function(){
$("#body_con").on( "swipeleft", swipeleftHandler );

function swipeleftHandler(event) {
alert('yes');
}
});

$(function() {
$("#body_con").on("swipeleft", function() {
alert('yes');
});
});


Changing jQuery to 2.2.0 fixed the problem, but then I had the problem of <input> tags not staying inline again.

I went through literally every version and variation I could find, starting at the top and working my way down. And FINALLY, this combination seemed to fix both issues:

<script src="//code.jquery.com/jquery-2.2.4.min.js"></script>
<script src="//code.jquery.com/mobile/1.2.1/jquery.mobile-1.2.1.min.js"></script>

I know that 3.x fixed a lot of issues, including a few security updates, so I'm not thrilled about moving backwards. But until a new Mobile version is released that is compatible with 3.x, I don't think that I have a choice.

Unless you guys can suggest a workaround to make the above code work?