0

I have a page that has a table with ID as below

<table id="T1">
<tbody>
<tr>
<td>Qassas</td>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
</tr>

<tr>
<td>test</td>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
</tr>
</tbody>

</table>

Via Page URL (I think I need to use something like XMLHttpRequest),

  • How can I get an element (Table) with its ID?

    • Then check if the qassas value exists in a table "T1" **in this page, retrieve the values of all tds beside the cell that contains the matched value qassas

P.S: the value is located in the first column

Any help would be fully appreciated

8
  • When you say Page URL, do you mean that the page is not open yet? Is this somehow related to pages stored in any SharePoint library? Commented Oct 18, 2017 at 19:11
  • yes, the page is not open yet, it's not related to SharePoint, it's HTML page on my site! Commented Oct 18, 2017 at 19:12
  • Are you able to get the page via Javascript? i.e. the html string of the page? Commented Oct 18, 2017 at 19:15
  • can you give us this url please ? Commented Oct 18, 2017 at 19:43
  • Sure blog.devoworx.net/test Commented Oct 18, 2017 at 19:46

1 Answer 1

1

Not possible to get the HTML content of a page if you've not access to this page, and not written a script that return the content.

I support my answer with this Stackoverflow question: How to get html source code from external url

Otherwise, if want to check if the value Qassas exist inside the table T1 you need to use the jQuery selector :contains, here is a simple demo:

//This Script check if "Qassas" exist in the table or not
if( $('#T1 td:contains("Qassas")').length  > 0)
{
  alert("Qassas exist");
}else
{
  alert("Qassas doesn't exist");
}

//This script retrieve the values of the closest "td" tags

var tr=$('#T1 td:contains("Qassas")').parent();
var values=[];
tr.children().each(function(){
  values.push($(this).text());
});
console.log(values);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table id="T1">
    <tbody>
    <tr>
    <td>Qassas</td>
    <td>1</td>
    <td>2</td>
    <td>3</td>
    <td>4</td>
    </tr>
    
    <tr>
    <td>test</td>
    <td>1</td>
    <td>2</td>
    <td>3</td>
    <td>4</td>
    </tr>
    </tbody>
    
    </table>

Sign up to request clarification or add additional context in comments.

8 Comments

Thank you, I got it what about the second request of search in table for a specific value, please post it to accept the answer
just click on the check mark, that you'll find at the left side of my answer. Good Luck
No Problem, I will. but I need to check if a value exists in a table "T1" get the td values besides! I mentioned this in my question, could you help me for this?!
@M.Qassas I edited my answer to show you how to check if Qassas exist or not
@M.Qassas sorry for that, I reedited my answer, you can get these values :) Good luck
|

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.