Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to change the text of an input using jquery

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 269
    Comment on it

    How to change the text of an input using jquery

    We can change the text of an input with the help of attributeEquals selector in Jquery

    Syntax: $(attribute='value of the attribute')

    attribute can be : name , value, title, style, src, id, href,disabled, alt.


    For Example: let us change the text of the input.

    <html lang="en">
    <head>
    <meta charset="utf-8">
    <title>Example For attributeEquals </title>
    <script src="https://code.jquery.com/jquery-1.10.2.js"></script>
    </head>
    <body>
    <div>
        <label>
        <input type="radio" name="a1" >
        <span>Input value?</span> <!-- The text Input value? will be replaced by Changed Text -->
        </label>
    </div>
    <div>
        <label>
        <input type="radio" name="a2" >
        <span>Input</span> <!--The text Input will be replaced by Changed Text-->
        </label>
    </div>
    <div>
        <label>
        <input type="radio" name="a3" >
        <span>Hello There</span> <!--The text Hello There will be replaced by Changed Text -->
        </label>
    </div>
    
    <script>
    $("input[name='a2']").next().text("Changed Text" ); <!-- here we used name attribute of an html element to change the text.-->                                                    
    
    </script>
    </body>
    </html>
    

    Output:

    Input value?
    Changed Text
    Hello There

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: