views:

88

answers:

3

I just want to select the text in a paragraph when I click or double click the "p" tag.Not highlight,just like using mouse to make a select area to choose text to be selected!

thank you very much!!

I am so sorry!

It is about a web page function.I have several paragraph and *.rar file link address on the page, and I want to select all the text when I click on one of them. I think the textbox could work that way.But I just like it to be in a paragraph or link tag!! So I can using the flashgot "downloading the link you selected".

SO, is it a way to select all text in paragraph by clicking the the another element?? Such as title 'h' tags??

+2  A: 

If you are talking about JavaScript, look at Introduction to Range by Peter-Paul Koch (famous for his compatibility tables).

alex
I am so sorry! It is about a web page function.I have several paragraph on the page, and I want to select all the text when I click on one of them.
qinHaiXiang
I had tried using text box to hold the file link address,when I focus and select the text in the textbox.The flashgot work well.But when I de-select the text box,flashgot remain holding the file link address!
qinHaiXiang
A: 

You CAN select a whole paragraph with a double click. Why do you want to change that?

netrox
Yeah.I am so stupid.But is it a way to select the paragraph text by click another element ,such as the title "h" tag!?
qinHaiXiang
A: 

Here's a function that will select the contents of the element you pass to it:

function selectElementContents(el) {
    var range;
    if (window.getSelection && document.createRange) {
        range = document.createRange();
        var sel = window.getSelection();
        range.selectNodeContents(el);
        sel.removeAllRanges();
        sel.addRange(range);
    } else if (document.body && document.body.createTextRange) {
        range = document.body.createTextRange();
        range.moveToElementText(el);
        range.select();
    }
}

window.onload = function() {
    var el = document.getElementById("your_para_id");
    selectElementContents(el);
};
Tim Down
Perfect! I thought it was the alternative way to get my target.Thank you very much!!
qinHaiXiang