JSFiddle - React, Tailwind, and code Playground

HTML

<div id="a" class="input1 foo"></div>
    <div id="b" class="foo input2"></div>
    <div id="c" class="xinput3 foo"></div>

JavaScript

$(function () {
            console.log("calling wrong");
            getAllInputDivsWrong().each(function () {
                console.log($(this).attr("id"));
            });

            console.log("calling right");
            getAllInputDivs().each(function () {
                console.log($(this).attr("id"));
            });
        });

        function getAllInputDivsWrong() {
            return $("div[class^='input']");            
        }

        function getAllInputDivs() {
            return $("div").filter(function (i, currentDiv) {
                return $.grep($(currentDiv).attr("class").split(" "), function (val) {
                    return val.substr(0, "input".length) === "input";
                }).length > 0;
            });
        }