Q:

How to differentiate between DOM elements in jQuery

I have some code that loops over each row of the table and creates a json object. The elements in the rows can be either of the following:
<input type="text" id="myelem"/>

or
<p id="myelem">foo</p>

Notice that the id attribute for the both is same. This is because on the table there is a button Add a new Row when this button is clicked another row is added to the table with a checkbox. When user submits the form the checkbox goes away and the value they entered turns into <p id="myelem">value they entered</p>
Below is the code I'm using for this. 
    $('.input-row').each(function(index, row) {
        var innerObject = {};
        var key = $('#myelem', row).val().toUpperCase();
        jsonObject[key] = "bar";
    });

The above works fine for textboxes becuse I'm using the .val() function. However, how do I get the data from the row if it contains <p id="myelem">foo</p> ??
my pseudo code would be something like this:
    $('.input-row').each(function(index, row) {
        var innerObject = {};
        /*
        if #myelem is a text box then use .val()
        if #myelem is a <p> tag then use .html()
        */
        var key = $('#myelem', row).val().toUpperCase();
        jsonObject[key] = "bar";
    });

A:

ids should always be globally unique on a page.  If you need multiple elements to be referenced, you should use classes.  If you set myelem as a class rather than an id you could then reference it like this 
$('.input-row .myelem')

A:

You can check which type the element is with 
var value = null;
if($('#myid').is('input')) {
    value = $('#myid').val();
}
else if($('#myid').is('p')) {
    value = $('#myid').html();
}

