0

I have a string of HTML tags and i want to retrieve all the attribute named 'name'. What should i do?

<input type="radio" name="read"/>

<input type="radio" name="write"/>

<input type="radio" name="speak"/>

I want to get read, write and speak.

1
  • 1
    See .attr() or .prop() Commented May 10, 2015 at 5:51

2 Answers 2

2

Use each if you have multiple elements on the page:

$('input').each(function() {
    console.log($(this).attr('name'));
});
Sign up to request clarification or add additional context in comments.

Comments

1

try this

$(document).ready(function(){
    var string = '<input type="radio" name="read"/><input type="radio" name="write"/><input type="radio" name="speak"/>';
    getStringname(string);
});


function getStringname(string){
    $('body').append('<div id="createdDivforinput" style="display:none;">'+string+'</div>');
    $('#createdDivforinput input').each(function() {
        alert($(this).attr('name'));
    });
    $('#createdDivforinput').remove();
}

Demo Here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.